Dear expert,
after some checks I get a data set with the following structure:
data b;
input type: $12. variable: $12. variable_min;
datalines;
date begin 2000
num price 3000
date end 2500
;run;
How can I show for the same variable (variable_min) in some cases (when type='date') as date and in some cases (when type='num') as numeric?
Thanks in advance, SH.
Have a character variable (only character can hol any value):
data b; length result $200; input type: $12. variable: $12. variable_min; select(type); when("date") result=put(variable_min,date9.); when("num") result=put(variable_min,best.); otherwise; end; datalines; date begin 2000 num price 3000 date end 2500 ; run;
Then put your number data in the correct text format.
Dear expert,
after some checks I get a data set with the following structure:
data b;
input type: $12. variable: $12. variable_min;
datalines;
date begin 2000
num price 3000
date end 2500
;run;
How can I show for the same variable (variable_min) in some cases (when type='date') as date and in some cases (when type='num') as numeric?
Thanks in advance, SH.
It depends on what you mean by "show". If you mean display in the log then you can
precise the display format in the put statement :
data b;
input type: $12. variable: $12. variable_min;
if type="date" then do;
put variable_min= date6.;
end;
else do;
put variable_min;
end;
datalines;
date begin 2000
num price 3000
date end 2500
;
run;
Repeating the question without additional information is not very helpful.
of course, sorry I did it by mistake.
You would have to show the output you want for your example data? Do you want to create a new variable or are attempting to do the desired display in another procedure (unlikely to work).
Have a character variable (only character can hol any value):
data b; length result $200; input type: $12. variable: $12. variable_min; select(type); when("date") result=put(variable_min,date9.); when("num") result=put(variable_min,best.); otherwise; end; datalines; date begin 2000 num price 3000 date end 2500 ; run;
Then put your number data in the correct text format.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.