Help using Base SAS procedures

Data concatenation with proc sql

Reply
N/A
Posts: 0

Data concatenation with proc sql

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.
Frequent Contributor
Posts: 102

Re: Data concatenation with proc sql

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;
Frequent Contributor
Posts: 102

Re: Data concatenation with proc sql

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;
N/A
Posts: 0

Re: Data concatenation with proc sql

Thanks Curtis. Dataset 'One' is already unique [one row per subjid]. Sorry, I left this info out. But you got it anyway ;-)
Ask a Question
Discussion stats
  • 3 replies
  • 97 views
  • 0 likes
  • 2 in conversation