BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
geneshackman
Pyrite | Level 9

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

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Using MultiLabel formats in PROC SUMMARY force the variable in the OUTPUT data set to be character.

--
Paige Miller

View solution in original post

9 REPLIES 9
PaigeMiller
Diamond | Level 26

Using MultiLabel formats in PROC SUMMARY force the variable in the OUTPUT data set to be character.

--
Paige Miller
geneshackman
Pyrite | Level 9

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.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
geneshackman
Pyrite | Level 9
Thanks. It is three groups, but one (New York State) overlaps with the other two. But I think I'll try some other ways now .....
geneshackman
Pyrite | Level 9
I mean, I want cos in the output data set, generated by proc summary, to be numeric.
PaigeMiller
Diamond | Level 26

@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.

--
Paige Miller
Tom
Super User Tom
Super User

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;

 

geneshackman
Pyrite | Level 9
Yes, thanks. I just wanted to see if i could do it without another data step. But I can do this too.
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 9 replies
  • 1407 views
  • 3 likes
  • 3 in conversation