Hi ... this is a really old post (2009), but it's a chance to learn something new.
You can transpose data with PROC SUMMARY. See the paper ...
Transposing Data Using PROC SUMMARY'S IDGROUP Option
John King, Ouachita Clinical Data Services, Mount Ida, AR
Mike Zdeb, U@Albany School of Public Health, Rensselaer, NY
http://www.lexjansen.com/pharmasug/2009/tt/tt08.pdf
For the posted data ...
data one;
input
cell_code: $5.
dropcode
mail_date : mmddyy.
seed : $1.
;
format mail_date mmddyy10.;
datalines;
NR800 1 12/07/2009 N
NR800 1 12/07/2009 Y
NR801 1 12/07/2009 N
NR801 1 12/07/2009 Y
NR801 2 12/07/2009 N
;
run;
* find the maximum number of observations within a CELL_CODE;
proc sql noprint;
select max(obs) into :obs
from
(select count(*) as obs
from one
group by cell_code)
;
quit;
* use PROC SUMMARY to transpose the data (use the macro variable from PROC SQL) ... SAS names the new variables;
proc summary nway data=one missing;
class cell_code;
output out=two (drop=_type_ _freq_) idgroup(out[&obs](dropcode mail_date seed)=);
run;
proc print data=two;
run;
cell_ dropcode_ dropcode_ dropcode_ mail_date_ mail_date_ mail_date_
code 1 2 3 1 2 3 seed_1 seed_2 seed_3
NR800 1 1 . 12/07/2009 12/07/2009 . N Y
NR801 1 1 2 12/07/2009 12/07/2009 12/07/2009 N Y N
OK.Let me try it. Since I like data step more,and MikeZdeb 's order of
variable maybe is not what you need.
data temp; infile datalines dlm=' '; input cell_code $ dropcode mail_date : mmddyy10. seed $; format mail_date mmddyy10.; datalines; NR800 1 11/07/2009 N NR800 1 12/07/2009 Y NR801 1 10/07/2009 N NR801 1 11/07/2009 Y NR801 2 12/07/2009 N ; run; data _null_; set temp end=last; by cell_code notsorted; if _n_ eq 1 then call execute('data want;'); if first.cell_code then count=0; count+1; call execute(cats('cell_code',count,'="',cell_code,'";') ); call execute(cats('dropcode',count,'=',dropcode,';')) ; call execute(cats('mail_date',count,'=',mail_date,';') ); call execute(cats('seed',count,'="',seed,'";')) ; if last.cell_code then call execute('output;'); if last then call execute('format mail_date: mmddyy10.;run;'); run;
Ksharp
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.