Hi guys!
I have a variable named 'becog,' and its value is 'second complete remission /third complete remission.' In the final output, I need to change them to '2nd' and '3rd.' So, I used the following format:
proc format;
value $remiss
"SECOND COMPLETE REMISSION"="2nd"
"THIRD COMPLETE REMISSION"="3rd";
run;Up to this point, everything is fine. Now, I need to add a row at the top in the 'becog' column as a label, and this label should be 'Current remission status.' It's quite long, so I named the column for this label 'col1' and also renamed 'becog' to 'col1' so that they can be merged. However, the problem arises because I formatted 'becog' initially. After the merge, my label is automatically truncated to three characters, similar to the format. How can I modify them to merge correctly?
Here is what I want to output:
that's what I get:
my code:
%macro con_stat1(varc= , label= );
proc freq data=ADSL noprint;
tables Trt01an *&varc / missing outpct out=&varc;
run;
proc freq data=ADSL noprint;
tables trt01an/missing out=&varc._n (drop=percent);
run;
data &varc._total1;
set &varc &varc._n;
by trt01an;
format &varc $&varc..;
run;
data &varc._total2(drop=pct_row count);
set &varc._total1;
length value $11. col1 $30.;
if &varc ne " " then do;
value=put(count,3.)|| "(" || put(pct_row,4.1)||"%)";
col1=strip(&varc);
end;
else if &varc eq " " then do;
value=put(count,3.);
col1=strip(-1);
end;
run;
proc sort data=&varc._total2;
by &varc;
run;
proc transpose data=&varc._total2
out=&varc._final1 (drop=_name_)
prefix=Trt;
by col1;
var value;
id Trt01an;
run;
data label;
length col1 $30;
col1="&label";
run;
data &varc._final2;
set label &varc._final1 ;
run;
data &varc._final3;
set &varc._final2;
if &varc=" " then label="n";
run;
%mend;
%con_stat1(varc=remiss,label=Current remission Status Score);
Well, it's going to be difficult for us to test, since you have the data and we don't. But here is something worth trying.
It is possible the transposition has assigned a format of $3 for your output. Examine the results with a PROC CONTENTS to verify that this is what is happening. Then change the format by adding a line:
data &varc._final3;
set &varc._final2;
if &varc=" " then label="n";
format &varc col1 label $30.;
run;
This is overkill, since you likely don't need all three variables formatted as $30. It is also possible that this issue has to be addressed slightly earlier in your program. If your investigation shows that to be the case, you might have to create data (using a DATA step) with fake data that we can use for testing purposes.
But changing the format in the right place should put you on the right path.
Hi @Sikcion,
I think you should increase the default length of format $REMISS. in your PROC FORMAT step so that it matches the length of variable COL1:
value $remiss (default=30)
This works!!! Thank you
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.