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;
Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.
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.