BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
magicdj
Fluorite | Level 6

I have a problem with the variable name split. please see screen shot below. I combine cohort and unit together. how can I split (L) to below Fmax,  like(mg/kg)below Mmin. thanks a lot

currently program auto split, there should be a way to manually split.

 

ods escapechar='^';

proc sort data=sashelp.class out=class;
    by sex;
run;

data c1;
    set class;
    length sexf $50.;
    Weightln=log10(Weight);

    if sex='M' then
        do;
            sexf2=strip(sex)||'min';
            unit='mg/kg';
        end;

    if sex='F' then
        do;
            sexf2=strip(sex)||'max';
            unit='L';
        end;
    sexf=strip(sexf2)||' ('||strip(unit)||')';

    if index(sexf, 'max') then
        sexf=tranwrd(sexf, 'max', '^{sub max}');

    if index(sexf, 'min') then
        sexf=tranwrd(sexf, 'min', '^{sub min}');
run;

proc sort data=c1;
    by sexf;

PROC MEANS DATA=c1 NOPRINT;
    BY sexf;
    VAR Weight;
    OUTPUT OUT=AB N=N0 MEAN=Mean0 CV=CV0 STD=SD0 STDERR=SE0 LCLM=LCLM UCLM=UCLM 
        MIN=MIN0 Q1=Q10 MEDIAN=Median0 Q3=Q30 MAX=MAX0;
RUN;

proc means data=c1 noprint;
    var Weightln;
    by sexf;
    output out=cd mean=logmean var=varlog;
run;

data gcd;
    set cd;
    geomean=round(exp(logmean), .001);
run;

proc sql;
    create table all as select a.*, b.geomean from AB a left join gcd b on 
        a.sexf=b.sexf;
quit;

proc format;
    picture mnf (round) low-high='009.99';
    picture sdf (round) low-high=' 009.99)' .='N/A)' (prefix='(');
    picture minf (round) low-high='009.99;' (prefix='[');
    picture maxf (round) low-high='009.99]';
run;

PROC tabulate data=all ORDER=data;
    CLASS sexf;
    VAR n0 MEAN0 SD0 se0 cv0 q10 median0 q30 MIN0 MAX0 geomean;
    keyword mean / style=[just=R];
    keyword StD / style=[just=L];
    TABLE (n0='n'*max=''*f=4. mean0='Mean'*max=''*[style=[just=R cellwidth=70] 
        f=mnf.] SD0='(SD)'*max=''*[style=[just=L cellwidth=75] f=sdf.] 
        SE0='SE'*max=''*f=8.2 cv0='CV%'*max=''*f=8.2 Q10='Q1'*max=''*f=8.2 
        median0='Median'*max=''*f=8.2 Q30='Q3'*max=''*f=8.2 
        min0='Tmin'*max=''*f=minf. max0='Max'*max=''*f=maxf.), sexf=" " / 
        misstext='---' box=" sex" RTS=30;
RUN;

 

test.jpg

 

1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ

Hi:

  I thought you wanted to change the value for the SEXF variable so that there was a line break after the subscript max. In the code you posted, you do this:

 if index(sexf, 'max') then
        sexf=tranwrd(sexf, 'max', '^{sub max}');

so you know how to use ODS ESCAPECHAR. The ways to force the line to split for that column header are either 1) make the column width narrower to force (L) to the next line -- which may not work as you expect or 2) (a more reliable option) use ODS ESCAPECHAR to insert a line break or carriage return or new line into the string.

 

  The previous posting that someone sent you showed the use of ESCAPECHAR+n, which is the older form of  the new line function. If you were going to use the newline function, it would be as shown below -- I just used SASHELP.CLASS and a format for the column headers instead of changing the variable name, but you can see the whole string you need to use to force a line break where you want:

sub_linefeed.png

 

Hope this helps,

Cynthia

View solution in original post

4 REPLIES 4
magicdj
Fluorite | Level 6

I actually mean the variable name split, not the header.

Cynthia_sas
SAS Super FREQ

Hi:

  I thought you wanted to change the value for the SEXF variable so that there was a line break after the subscript max. In the code you posted, you do this:

 if index(sexf, 'max') then
        sexf=tranwrd(sexf, 'max', '^{sub max}');

so you know how to use ODS ESCAPECHAR. The ways to force the line to split for that column header are either 1) make the column width narrower to force (L) to the next line -- which may not work as you expect or 2) (a more reliable option) use ODS ESCAPECHAR to insert a line break or carriage return or new line into the string.

 

  The previous posting that someone sent you showed the use of ESCAPECHAR+n, which is the older form of  the new line function. If you were going to use the newline function, it would be as shown below -- I just used SASHELP.CLASS and a format for the column headers instead of changing the variable name, but you can see the whole string you need to use to force a line break where you want:

sub_linefeed.png

 

Hope this helps,

Cynthia

magicdj
Fluorite | Level 6

Cynthia, thanks a lot, it works!!!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 4 replies
  • 1601 views
  • 4 likes
  • 3 in conversation