BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
michtka
Fluorite | Level 6

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

1 ACCEPTED SOLUTION

Accepted Solutions
michtka
Fluorite | Level 6

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;

View solution in original post

2 REPLIES 2
Reeza
Super User

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;

michtka
Fluorite | Level 6

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1017 views
  • 3 likes
  • 2 in conversation