11-21-2013 10:12 AM
I have a question regarding formats
I have numeric variable AGE and I want to give ranges while I write formats
age is integer here
value afefmt /*WHEN DO I NEED TO PUT A DOLLAR SIGN HERE......SINCE THE VARIABLE WE HAVE IS NUMERIC .THERE IS NO $ SIGN???????
11-21-2013 10:29 AM
You only need a $ format if the use will be for character formats. If your ages were character you would use
value $agefmt ..
though you'd likely get unexpected results.
11-21-2013 10:53 AM
Unexpected results come from the sort of character variables: "9" is > "10" as the comparison generally starts with the first characters. So ranges like "1" - "20" are valid in proc format but values of "3", "4", "5" are not between "1" and "20" .
See what happens with this code:
length x $ 2;
input x $;
proc sort; by x;run;
11-27-2013 01:52 PM
Not sure what your exact question is. If I am following it then here is the response:
Proc format can be used to format numeric variables and assign them a range. The advantage of that is you can presentt the data using proc report or proc freq as a range; whereas for analysis of numeric data like proc means it will treat this as a continuous variable.
Test the code below using examples of proc freq and proc means. In the freq procedure the output will be range. In the means procedure the age will be rightly handled as a numeric variable.
value age 1-19='0-19'
proc freq data=test;
format age age.;
proc means data=test;