BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Kurt_Bremser
Super User
A numeric format must have numeric arguments to the left of the equal sign. Look at the raw, unformatted values in your dataset to determine which ones to use.
Jacob6
Calcite | Level 5

Jacob6_0-1707885553900.png

are you refering to this? or should i look at a data dictionary.

Kurt_Bremser
Super User

These are the formatted values of SUB1. The unformatted values can be seen in your PROC FREQ output where the format was disabled.

Or you can run this:

proc sql;
select distinct
  sub1 format=best. as sub1_unf,
  sub1
from tedsa_puf_2021
;
quit;

to get the value pairs contained in your dataset.

Jacob6
Calcite | Level 5

Jacob6_0-1707943185518.png

so would i now input the corresponding numbers? 

 

 

 

Jacob6
Calcite | Level 5

Jacob6_0-1707970305309.png

i get this 

Kurt_Bremser
Super User

You have to cover all of the numeric values in your format; those that have no explicit assignment in the format will be taken as-is.

Tom
Super User Tom
Super User

Why didn't you just look at the format that you imported from the CPORT file?

NOTE: PROC CIMPORT begins to create/update catalog WORK.FORMATS
...
NOTE: Entry SUB.FORMAT has been imported.

You can convert a format into dataset using PROC FORMAT and CNTLOUT= option.

proc format cntlout=sub_format;
  select sub;
run;
proc print data=sub_format;
  var start end label;
run;
Reeza
Super User

I would probably hard code it, since you don't seem super familiar with formats/recoding.

 

data tedsa_puf_2021_combined;
set tedsa_puf_2021;


length sub1_combined$100.;

if sub1 in (2, 14, 15) then sub1_combined = 'Alcohol, Barbiturates, Other Tranquilizers';
else sub1_combined= put(sub1, sub.);
run;

proc freq data=tedsa_puf_2021_combined;
table sub1_combined*region;
run;

 

Jacob6
Calcite | Level 5

i got this

 

Jacob6_0-1707971286638.png

 

Reeza
Super User
And that is not what you want?
Jacob6
Calcite | Level 5

it is. how do i apply this to combining other ones?

Tom
Super User Tom
Super User

@Jacob6 wrote:

it is. how do i apply this to combining other ones?


I suspect that if you just take the time to clarify what exactly you are asking for you will already have created the code you need.

Reeza
Super User
Please be more descriptive in your responses, you'll get faster and better answers.

What other ones are you referring to? Other variables? Other SUB1 values?

If you need to recategorize the variable combining multiple categories rather than just one, it's better to get the format extracted and then manually change the values from the proc format and apply the new format.

Or copy my structure and add more IF statements to categorize based on your codes.
Tom
Super User Tom
Super User

You cannot use a CHARACTER format, like $MYCAT, with a NUMERIC variable, like SUB1.

 

Why did you create a character format if SUB1 was a numeric variable?

What are the values of SUB1?  Why did you think they were the text strings you use to create the $MYCAT format?  Did SUB1 already have a user defined numeric format attached to it that was causing the numbers to display as those strings?  If so then make a numeric variable, perhaps named MYCAT instead , that maps the numeric values to the text string you want to display.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 32 replies
  • 1907 views
  • 1 like
  • 7 in conversation