are you refering to this? or should i look at a data dictionary.
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.
so would i now input the corresponding numbers?
Yes. An example line would be
2,15,14 = "Combined ABT"
i get this
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.
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;
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;
i got this
it is. how do i apply this to combining other ones?
@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.
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.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Select SAS Training centers are offering in-person courses. View upcoming courses for: