PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, November 10, 2022

[FIXED] Why is my proc format changing unrelated variables?

 November 10, 2022     format, proc, sas     No comments   

Issue

This is my proc format code:

Proc format;
value $fmtempty
" " = "unknown"
;
run;

This is my application to the data set:

DATA ASSIGN1.TRAININGCOPY;

SET TRAININGCOPY;

FORMAT job education $fmtempty.;

RUN;

At first it seemed to work but the table just comes out "goofy".

  1. it cuts of the names of the rest of my variables, ex management becomes managem

  2. when I run this code:

    proc freq data= ASSIGN1.TRAINING; tables job; run;

for job, my frequency empty goes from 4 to 42. oddly, when I visually inspect and filter the data, the missing data has been filled in as expected, and I can't find any missing data. I have similar results with education.

original          converts to
1   blue-collar  1 bluec
2                2 unknown      
3   management   3 managem  
4   student      4 stude
5   technician   5 techni
6   blue-collar  6 bluec

Any suggestions of what I'm doing wrong or even an explanation of what's actually happening would be greatly appreciated. Thank you in advance.


Solution

Change the Proc FORMAT value statement to use the (default=N) option. N defines how much width to allocate for the format when no width is specified in a FORMAT statement.

Example:

data have;
input text $char20.;
datalines;
blue-collar
            
management 
student    
technician 
blue-collar
;

proc format;
  value $fmtempty (default=20)
    " " = "unknown"
  ;
run;

data want;
  set have;
  format text $fmtempty.;
run;

Output data set
enter image description here



Answered By - Richard
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing