Hi guys, I would like you to help me with this:
I got the next dataset:
text drug placebo
randomized 100 101
treated 100 100
completed 90 85
discontinued 10 16
I would like to built this dataset:
test drug placebo
randomized 100 101
treated 100 (100/100) 100(101/100)
completed 90 (90/100) 85(85/101)
discontinued 10(10/100) 16(16/101)
As you can see, my idea is to keep the first record of the dataset, 100 and 101 and assigned a variable to these as r1=100 and r2=101,
then write down something like:
drug=drug||' ' || (drug/r1);
placebo=placebo||''||(placebo/r2)
I know is very simplistic, for thsi reason I would like you to help me to write a piece of code maybe using call symput or symget to create the macrovariables r1 and r2,,
or maybe usinf the retain option to keep the first record.
Thanks in advance
J V
Thanks, it works.
Example:
data new;
set sashelp.class (keep=name age);
age2=age*2;
run;
data new2 (drop=age_n age2_n age age2);
length agen $20 age2n $20;
set new;
retain age_n age2_n;
if _n_=1 then do;
age_n=age;
age2_n=age2;
agen=put(age,3.);
age2n=put(age2,3.);
end;
else do;
agen=put(age,3.)||' '||'('||put((age/age_n)*100,6.2)||')';
age2n=put(age2,3.)||' '||'('||put((age2/age2_n)*100,6.2)||')';
end;
run;
You don't need macro variables you need retained variables within your dataset.
data have;
set want;
retain placebo_n drug_n;
if _n_=1 then do;
placebo_n = placebo;
drug_n=drug;
new_placebo=placebo;
new_drug=drug;
end;
else do;
drug2=drug|| " (" ||drug"/" blah blah;
placebo2=placebo2 || ...blah blah;
end;
run;
Thanks, it works.
Example:
data new;
set sashelp.class (keep=name age);
age2=age*2;
run;
data new2 (drop=age_n age2_n age age2);
length agen $20 age2n $20;
set new;
retain age_n age2_n;
if _n_=1 then do;
age_n=age;
age2_n=age2;
agen=put(age,3.);
age2n=put(age2,3.);
end;
else do;
agen=put(age,3.)||' '||'('||put((age/age_n)*100,6.2)||')';
age2n=put(age2,3.)||' '||'('||put((age2/age2_n)*100,6.2)||')';
end;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.