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 😉

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 789 views
  • 0 likes
  • 2 in conversation