Hello
X_char is a char var.
I run following code and expext that resulted VAR (W) be char with values-1,2,3,4
My question- Why VAR W is numeric???
proc format ;
value $F1_High_Risk_ithalv
'High_50-100%-Med_0-50%-Low_0-50%',
'High_50-100%-Low_0-50%',
'High_100%',
'High_50-100%-Med_0-50%',
'High_0-50%-Med_50-100%-Low_0-50%',
'High_0-50%-Med_50-100%',
'Med_50-100%-Low_0-50%',
'Med_100%'
=1
'High_0-50%-Med_0-50%-Low_50-100%',
'Med_0-50%-Low_50-100%',
'High_0-50%-Low_50-100%'
=2
'High_0-50%-Med_0-50%-Low_0-50%',
'ithalv=0'
=3
'Low_100%'
=4
;
Run;
W=put(compress(X_CHAR),$F1_High_Risk_ithalv.);
It's not numeric!
data test;
x_char='High_50-100%-Med_0-50%-Low_0-50%';
W=put(compress(X_CHAR),$F1_High_Risk_ithalv.);
run;
proc contents;
run;
SAS just let's you to be a "lazy typer".
Even though you provide values 1,2,3 without quotes, since you are defining character format, the values 1,2,3, are interpreted as they were "1", "2", "3".
Of course for better readability adding "" would be good idea.
Bart
It's not numeric!
data test;
x_char='High_50-100%-Med_0-50%-Low_0-50%';
W=put(compress(X_CHAR),$F1_High_Risk_ithalv.);
run;
proc contents;
run;
SAS just let's you to be a "lazy typer".
Even though you provide values 1,2,3 without quotes, since you are defining character format, the values 1,2,3, are interpreted as they were "1", "2", "3".
Of course for better readability adding "" would be good idea.
Bart
Because FORMATs convert VALUES into TEXT. The result of using PUT() is ALWAYS going to be character.
If you want to create a numeric value you need to use an INFORMAT with the INPUT() function. INFORMATs convert TEXT into VALUES.
proc format ;
invalue F1_High_Risk_ithalv
'High_50-100%-Med_0-50%-Low_0-50%'
,'High_50-100%-Low_0-50%'
,'High_100%'
,'High_50-100%-Med_0-50%'
,'High_0-50%-Med_50-100%-Low_0-50%'
,'High_0-50%-Med_50-100%'
,'Med_50-100%-Low_0-50%'
,'Med_100%'
=1
'High_0-50%-Med_0-50%-Low_50-100%'
,'Med_0-50%-Low_50-100%'
,'High_0-50%-Low_50-100%'
=2
'High_0-50%-Med_0-50%-Low_0-50%'
,'ithalv=0'
=3
'Low_100%'
=4
;
run;
data test ;
input x_char $80.;
W=input(compress(X_CHAR),F1_High_Risk_ithalv.);
cards;
Low_100%
Med_100%
High_0-50%-Low_50-100%
ithalv=0
;;;;
proc print;
run;
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.