Hi,
I am creating a shift table using below code. I have provided the data below. I am transposing 2 times, first transpose is for basecat1 values and my final transpose is for ANAGR2N. But my final transpose if not working I am getting 0 records. Is there any way we can do it in only one transpose or do I need to use different procedure to get counts? I am not sure where I am wrong. Can you please suggest. My expected output is below.
Thanks,
Adi
data have;
infile datalines dsd truncover;
input USUBJID:$30. ANAGR2N:32. PARAM:$200. PARAMCD:$8. AVALCAT1:$200. AVISIT:$200. AVISITN:32. avaln:32. BASECAT1:$200. basen:32.;
datalines4;
TAK-935-3001-09011-105,1,Mobility,EQ5D0201,No problems,V1,1,1,Missing,6
TAK-935-3001-63004-105,1,Mobility,EQ5D0201,No problems,V1,1,1,Missing,6
TAK-935-3001-09011-105,1,Mobility,EQ5D0201,Total,V1,1,9,Missing,6
TAK-935-3001-63004-105,1,Mobility,EQ5D0201,Total,V1,1,9,Missing,6
TAK-935-3001-09011-105,1,Mobility,EQ5D0201,No problems,V1,1,1,Total,9
TAK-935-3001-63004-105,1,Mobility,EQ5D0201,No problems,V1,1,1,Total,9
TAK-935-3001-09011-105,1,Mobility,EQ5D0201,Total,V1,1,9,Total,9
TAK-935-3001-63004-105,1,Mobility,EQ5D0201,Total,V1,1,9,Total,9
TAK-935-3002-02001-202,2,Mobility,EQ5D0201,No problems,V1,1,1,No problems,1
TAK-935-3002-04001-202,2,Mobility,EQ5D0201,No problems,V1,1,1,No problems,1
TAK-935-3002-04003-202,2,Mobility,EQ5D0201,No problems,V1,1,1,No problems,1
TAK-935-3002-04003-203,2,Mobility,EQ5D0201,No problems,V1,1,1,No problems,1
TAK-935-3002-07001-201,2,Mobility,EQ5D0201,No problems,V1,1,1,No problems,1
TAK-935-3002-07001-204,2,Mobility,EQ5D0201,No problems,V1,1,1,No problems,1
TAK-935-3002-09001-203,2,Mobility,EQ5D0201,No problems,V1,1,1,No problems,1
TAK-935-3002-09001-204,2,Mobility,EQ5D0201,No problems,V1,1,1,No problems,1
TAK-935-3002-09002-203,2,Mobility,EQ5D0201,No problems,V1,1,1,No problems,1
TAK-935-3002-09002-204,2,Mobility,EQ5D0201,No problems,V1,1,1,No problems,1
TAK-935-3002-09003-203,2,Mobility,EQ5D0201,No problems,V1,1,1,No problems,1
TAK-935-3002-09003-206,2,Mobility,EQ5D0201,No problems,V1,1,1,No problems,1
;;;;
run;
** Get count;
proc sort data=adqseq1_fin; by paramcd param avisitn avisit anagr2n basen avaln; run;
proc freq data=adqseq1_fin;
by paramcd param avisitn avisit anagr2n basen avaln;
tables avalcat1*basecat1 / out=step1;
run;
** Transpose basecat1;
proc sort data=step1; by paramcd param avisitn avisit avaln avalcat1 anagr2n; run;
proc transpose data=step1(where=(basen ne .)) out=step2(drop=_name_ _label_) prefix=_;
id basen;
var count;
by paramcd param avisitn avisit avaln avalcat1 anagr2n;
run;
** Transpose ANAGR2N;
data step2_;
set step2;
if anagr2n=1 then do;
_11=_1;
_12=_2;
_13=_3;
_14=_4;
_15=_5;
_16=_6;
_19=_9;
end;
if anagr2n=2 then do;
_21=_1;
_22=_2;
_23=_3;
_24=_4;
_25=_5;
_26=_6;
_29=_9;
end;
if anagr2n=3 then do;
_31=_1;
_32=_2;
_33=_3;
_34=_4;
_35=_5;
_36=_6;
_39=_9;
end;
drop _1 _2 _3 _4 _5 _6 _9;
run;
** Final traspose for ANAGR2N;
proc sort data=step2_; by paramcd param avisitn avisit avaln avalcat1 _:; run;
proc transpose data=step2_(where=(anagr2n ne .)) out=step3(drop=_name_) prefix=_;
id anagr2n;
by paramcd param avisitn avisit avaln avalcat1 _:;
run;
You can use the %TABLEN macro to produce such a table.
Please provide data as working SAS data step code (examples and instructions), as you did in earlier threads. We cannot work with data in screen captures. We cannot work with data in Excel. It must be in the form stated.
When something doesn't work, please provide us with the LOG for your code. We need to see the ENTIRE log for the step that has the error (the ENTIRE log for the step that has the error, not just the error messages). Copy the log as text and paste it into the window that appears when you click on the </> icon.
Maxim 2: Read the log
132 proc transpose data=step2_(where=(anagr2n ne .)) out=step3(drop=_name_) prefix=_; 133 id anagr2n; 134 by paramcd param avisitn avisit avaln avalcat1 _:; 135 run; NOTE: No variables to transpose.
You can't do a transpose if there are no variables to transpose. Why are there no variables to transpose? Because you told PROC TRANSPOSE that every variable in the data set is either an ID variable for PROC TRANSPOSE, or it is a BY variable for PROC TRANSPOSE, and so there's no variables left to transpose.
Can you show what the result is supposed to look like? Code that does not run or doesn't provide an output does not describe what the desired result may look like.
And are you sure that you need a data set? Sometime a report is more likely to generate output in a complex appearance.
You can use the %TABLEN macro to produce such a table.
It appears to me that you can do most of this in PROC TABULATE, and I imagine all of it in PROC REPORT.
I can offer a PROC TABULATE solution, but others will have to do the PROC REPORT.
But first, you have instances of "Total" for BASECAT1 and AVALCAT1. You haven't said what you want to do with them.
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 how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.