I have a numeric variable coded as 0/1
I want to create a character variable that would allow at least 11 characters in the word, can someone guide the best way to code this?
Thanks,
data have;
input drug;
cards;
0
1
0;
Run; I want to create a character variable such as
if drug1=1 then ch= 'healthinsurance'
Not sure i understand you req, do you mean assigning length for your char?
data have;
input drug;
cards;
0
1
;
Run;
data want;
set have;
length ch $20;
if drug=1 then ch= 'healthinsurance' ;
run;
The same way you would define the length for any variable in your data set. Use the LENGTH statement.
data want ;
length drug 8 ch $12 ;
input drug;
if drug then ch= 'healthinsurance' ;
cards;
0
1
;
Define a format with your translations, and the resulting variable (when the format is used in a put() function) will have the appropriate length.
proc format;
value mytrans
1 = 'healthinsurance'
0 = 'other'
;
run;
data want;
input numvar;
charvar = pu(numvar,mytrans.);
cards;
0
1
;
run;
@Kurt_Bremser wrote:
Define a format with your translations, and the resulting variable (when the format is used in a put() function) will have the appropriate length.
proc format; value mytrans 1 = 'healthinsurance' 0 = 'other' ; run; data want; input numvar; charvar = pu(numvar,mytrans.); cards; 0 1 ; run;
Or just use the FORMAT to display the value without creating another variable.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.