Hello All..
Is it possible to concatenate date variable and numeric variable together in Proc Report???
I am having two variables in my dataset DOB and Age..
I want to show there variables together in date column like 21Jan1988(25)
Is there any way???
Thanks ®ards..
Sanjeev.K
Hi!
One solution is to convert the values to text with the function PUT, and then create a text variable from this.
Mabye something like this:
/*Create data with numeric variables*/
data testData;
dob='21jan1988'd;
age=25;
run;
/*Create text variable for presentation*/
data testData;
set testData;
text=cats(put(dob,date9.),'(',put(age,3.),')');
run;
Hi!
Another way is to create a function with Proc Fcmp that calculates the age. From this, you can create a format that you can use on a date variable, to display both the date and the age.
Something like this:
/*Create function*/
proc fcmp outlib=work.myfunc.group;
function fmtfunc(dob) $ 20;
length text $ 20;
age=int(yrdif(dob,today(),'age'));
text=cats(put(dob,date9.),'(',put(age,3.),')');
return(text);
endsub;
run;
/*Tell Sas where to fund the function*/
options cmplib=work.myfunc;
/*Create a format that you can use on yout date variable*/
proc format;
value agefmt (default=20) other=[fmtfunc()] ;
run;
proc print data=testData;
format dob agefmt.;
run;
Hi Sanjeev,
you try the below code, using the compute block we can do that
data test;
input dob : date9. age;
format dob date9.;
cards;
21Jan1988 25
;
proc report data=test headline headskip missing nowd;
column dob age dob_age;
define dob / display;
define age / display;
define dob_age / computed;
compute dob_age / character length=100;
dob_age=put(dob,date9.)||'('||strip(put(age,3.))||')';
endcomp;
run;
Thanks,
Jag
data test;
input month $ sale;
datalines;
jan 2000
feb 1400
mar 2300
apr 3400
may 2700
jun 3200
july 800
aug 2900
sep 1700
oct 2100
nov 2600
dec 3200
;
run;
i m looking to convert month in num as 1 2 3 ,
for that i m tring it.
data test1;
set test;
mon_num=input(month,monname3.);
run;
proc print; run;
but its showing error. i need to short data by month. can we do it in short or sud i use if condition on each month????
not even a picture format can present two values in one PUT()
it needs a concatenation .
Why is it important to have two values in one cell?
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.