BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi: How to imitate the below data steps using proc sql:

data two;
set one (keep = subjid trt)
output;
trt = 99 /*** assuming trt values in one are 1 and 2 ***/
output;
run;

Thanks.
3 REPLIES 3
CurtisMack
Fluorite | Level 6
I don't think your psuedo code does what you think it does so I ran it to show the real results. Here it is with the SQL equivalent.

data one;
subjid = "Sub1";
trt = 1; output;
trt = 2; output;
subjid = "Sub2";
trt = 1; output;
trt = 2; output;
run;

data two;
set one (keep = subjid trt);
output;
trt = 99;
output;
run;

proc sql;
create table tow2 as
select subjid, trt
from one
union all
select subjid,99 as trt
from one;
quit;
CurtisMack
Fluorite | Level 6
This seems more likely to be what you were trying to do.


data two;
set one (keep = subjid trt);
by subjid;
output;
if last.subjid then do;
trt = 99;
output;
end;
run;

proc sql;
create table tow2 as
select subjid, trt
from one
union all
select subjid,99 as trt
from (select distinct subjid from one);
quit;
deleted_user
Not applicable
Thanks Curtis. Dataset 'One' is already unique [one row per subjid]. Sorry, I left this info out. But you got it anyway 😉
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
  • 3 replies
  • 1199 views
  • 0 likes
  • 2 in conversation