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

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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