Help using Base SAS procedures

Format Question

Reply
Super Contributor
Posts: 1,040

Format Question

Hi,

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

proc format;

value afefmt    /*WHEN DO I NEED TO PUT A DOLLAR SIGN HERE......SINCE THE VARIABLE WE HAVE IS NUMERIC .THERE IS NO $ SIGN???????

0-<20= "0-19"

Thanks

Super User
Posts: 10,516

Re: Format Question

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.

Super Contributor
Posts: 1,040

Re: Format Question

Yes i understand. Is the unexpected results because of the Range upper limits and lower limits?

Unless we specify with TILde ???

Regards

Super User
Posts: 10,516

Re: Format Question

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:

 

data temp;

length x $ 2;

input x $;

datalines;

1

20

3

4

5

6

7

11

;

run;

proc sort; by x;run;

proc print;run;

Contributor
Posts: 58

Re: Format Question

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.


data test;
input age;
datalines;
1
21
3
5
6
88
99
;
run;

proc format;
value age 1-19='0-19'
              20-99='>20'
;
quit;

proc freq data=test;
tables age;
format age age.;
run;

proc means data=test;
var age;
run;

Ask a Question
Discussion stats
  • 4 replies
  • 285 views
  • 0 likes
  • 3 in conversation