I hope this is a simple question. I have a program that includes a proc format and a proc summary. When I run the proc summary, the values in the class statement column (cos) come out character but I want them to be numeric. I want cos to be numeric. Can I do that?
** Here is the program **
proc format ;
value cos (multilabel)
1-62 = 999
1-57 = 888
58-62 = 102
;
run;
proc import
datafile= "T:\gxs03\Misc\exampledata.csv"
dbms=csv
out=example
replace;
run;
proc summary data=example nway ;
class cos / mlf ;
format cos cos.;
var count pop;
output out=exampleregion sum=;
run;
** Here are the data **
cos | count | pop |
1 | 35000 | 983 |
2 | 746 | 5 |
58 | 462158 | 49773 |
3 | 9534 | 319 |
59 | 760449 | 44365 |
** Here is the output**
cos | _TYPE_ | _FREQ_ | count | pop |
102 | 1 | 2 | 1222607 | 94138 |
888 | 1 | 3 | 45280 | 1307 |
999 | 1 | 5 | 1267887 | 95445 |
Using MultiLabel formats in PROC SUMMARY force the variable in the OUTPUT data set to be character.
Using MultiLabel formats in PROC SUMMARY force the variable in the OUTPUT data set to be character.
PaigeMiller, thanks, that's good to know. But the problem is that cos divides the groups into three, and one overlaps with the other two.
Cos is counties. 1-57 are New York State outside of New York City. 58-62 are New York City. And 1-62 is New York State, which overlaps with the other two.
proc format ;
value cos (multilabel)
1-62 = 999
1-57 = 888
58-62 = 102
;
run;
So I kind of have to use these three overlapping groups. 😞
But good to know "multilable" makes them character.
I don't understand the issue here. You have chosen to group the data 3 ways, and now it sounds like this is not what you want to do? Please explain in more detail.
@geneshackman wrote:
I mean, I want cos in the output data set, generated by proc summary, to be numeric.
Can't be done with multi-label formats.
Just change it to numeric by adding another step.
data want;
length cos 8;
set exampleregion (rename=(cos=string));
cos = input(string,32.);
drop string;
run;
In this case, the value of the format is unique and just digits, so it can be converted to numeric with an extra step. In other cases, the value of the format is not just digits, and cannot be easily converted (if it can be converted at all) to numeric.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.