BookmarkSubscribeRSS Feed
Sikcion
Fluorite | Level 6

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:

Screenshot 2024-01-04 at 1.04.31 AM.png

that's what I get:

Screenshot 2024-01-04 at 1.03.55 AM.png

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);
3 REPLIES 3
Astounding
PROC Star

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.

FreelanceReinh
Jade | Level 19

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)

 

Sikcion
Fluorite | Level 6

This works!!! Thank you

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
How to Concatenate Values

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.

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
  • 511 views
  • 2 likes
  • 3 in conversation