BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ayooo1
Obsidian | Level 7

How can I combine 2 separate datas to make a demographic table like this:

Characteristics   7ugkgday 9ugkgday 12ugkgday total

Sex

  male                xxx(xxx)   xxx(xxx)    xxx(xxx)     xxx(xxx)

  female             xxx(xxx)   xxx(xxx)    xxx(xxx)     xxx(xxx)

Age

  18-40               xxx(xxx)   xxx(xxx)    xxx(xxx)     xxx(xxx)

  41-64               xxx(xxx)   xxx(xxx)    xxx(xxx)     xxx(xxx)

  >=65                xxx(xxx)   xxx(xxx)    xxx(xxx)     xxx(xxx)

Ayooo1_0-1671713666116.png

Ayooo1_1-1671713712239.png

 

1 ACCEPTED SOLUTION

Accepted Solutions
tarheel13
Rhodochrosite | Level 12

The code you have written does not make sense. It makes more sense to do this: 

This will indent lines where chara is not equal to "Race n(%)"

if chara ne 'Race n(%)' then chara="   "||chara.                                                             

 

View solution in original post

10 REPLIES 10
Ayooo1
Obsidian | Level 7

I figured out the part to put everything under characteristics but now do I concatenate for that indentation. If so, how?

/*SEX*/
proc sort; by SUJID EXDSTXT; 
data Ex;
set Sasfile.EX;
keep SUBJID EXDSTXT;
by SUBJID EXDSTXT;
if first.SUBJID;
output;
EXDSTXT='Total';output;
run;
proc sort data=EX;
by SUBJID;
run;
data DmSEX;
retain SUBJID SEX;
set Sasfile.Dm;
if SEX="M" then SEX="Male";else SEX="Female";
keep SUBJID SEX;
run;
proc sort data=DmSEX;
by SUBJID;
run;
data M_EXDM;
merge Ex(in=a) DmSEX(in=b);
by SUBJID;
if a and b;
run;
proc sort data=M_EXDM;
by EXDSTXT;
run;
proc freq data=M_EXDM noprint;
tables SEX*EXDSTXT / nopercent out=FreqST;
by EXDSTXT;
run;
proc sort data=FreqST;
by EXDSTXT;
run;
proc freq data=M_EXDM noprint;
tables EXDSTXT/ nopercent out=FreqT (rename=(COUNT=Total));
by EXDSTXT;
run;
proc sort data=FreqT;
by EXDSTXT;
run;
data M_ST;
merge FreqT(in=a) FreqST(in=b);
by EXDSTXT;
if a and b;
run;
data M_ST_CP (keep= DoseC_P EXDSTXT SEX);
set M_ST;
by EXDSTXT;
retain COUNT PERCENT EXDSTXT SEX;
length DoseC_P $20;
DoseC_P= strip(put(COUNT,comma12.)||''|| put(-PERCENT/100,percent7.1));
run;
proc sort data=M_ST_CP;
by descending SEX;
run;
proc transpose data=M_ST_CP out=T_SEX (drop=_NAME_);
by descending SEX ;
id EXDSTXT;
var DoseC_P;
run;
data T_SEX;
retain SEX _7_ug_kg_day _9_ug_kg_day _12_ug_kg_day Total;
set T_SEX;
keep SEX _7_ug_kg_day _9_ug_kg_day _12_ug_kg_day Total;
by descending SEX;
if _9_ug_kg_day=" " then _9_ug_kg_day="0";
rename SEX=CHARA;
run;
data labelSEX;
length CHARA $50;
CHARA="Sex n(%)";
run;
data F_SEX;
set labelSEX T_SEX;
run;
/* AGE*/
data DmAGE;
retain SUBJID AGE CAT;
set Sasfile.Dm;
keep SUBJID CAT AGE;
length CAT $6;
if AGE >=18 and AGE < 40 then CAT = "18-40";
else if AGE >= 41 and AGE < 64 then CAT = "41-64";
else CAT = ">=65";
run;
proc sort data=DmAGE;
by SUBJID;
run;
data M_AGEEX;
merge Ex(in=a) DmAGE(in=b);
by SUBJID;
if a and b;
run;
proc sort data=M_AGEEX;
by EXDSTXT;
run;
proc freq data=M_AGEEX noprint;
tables CAT*EXDSTXT/ nopercent out=FreqAT;
by EXDSTXT;
run;
proc sort data=FreqAT;
by EXDSTXT;
run;
proc freq data=M_EXDM noprint;
tables EXDSTXT/ nopercent out=FreqT (rename=(COUNT=Total));
by EXDSTXT;
run;
proc sort data=FreqT;
by EXDSTXT;
run;
data M_AT;
merge FreqT(in=a) FreqAT(in=b);
by EXDSTXT;
if a and b;
run;
data M_AT_CP (keep= CATE EXDSTXT CAT);
set M_AT;
by EXDSTXT;
retain COUNT PERCENT EXDSTXT CAT;
length CATE $20;
CATE= strip(put(COUNT,comma12.)||''|| put(-PERCENT/100,percent7.1));
run;
proc sort data=M_AT_CP;
by CAT;
run;
proc transpose data=M_AT_CP out=T_AGE (drop=_NAME_);
by CAT;
id EXDSTXT;
var CATE;
run;
data T_AGE;
retain CAT _7_ug_kg_day _9_ug_kg_day _12_ug_kg_day Total;
set T_AGE;
keep CAT _7_ug_kg_day _9_ug_kg_day _12_ug_kg_day Total;
by CAT;
rename CAT=CHARA;
run;
data labelAGE;
length CHARA $50;
CHARA="Age (yrs)";
run;
data F_AGE;
set labelAGE T_AGE;
run;
data Final;
set F_SEX F_AGE;
run;
Kurt_Bremser
Super User

I asked for examples of your initial datasets, posted as data step code with DATALINES.

Code you tried and which doesn't work to your satisfaction anyway is not useful, especially without knowing the data.

tarheel13
Rhodochrosite | Level 12

To get the labels, you can make rows and put them in the dataset. Indentation, one way is to just hardcode the spaces by putting "    "||variable. 

Ayooo1
Obsidian | Level 7

I figured out the labels part but still not the indentation part. The red is what I can't figure out.

data F_Race;
length race $ 50;
set T_Race;
if RACE="BLACK OR AFRICAN AMERICAN" then RACE="Black";
if RACE="WHITE" then RACE="White";
if _7_ug_kg_day=" " then _7_ug_kg_day="0";
if _12_ug_kg_day=" " then _12_ug_kg_day="0";
rename race=CHARA;
run;
data labelRACE;
length CHARA $ 50;
CHARA="Race n(%)";
run;
data Fin_R;
set labelRACE F_RACE;
if 'Race n(%)' gt 2 then CHARA="	"||RACE;
run;

 

Ayooo1_0-1671765816759.png

 

 

tarheel13
Rhodochrosite | Level 12

The code you have written does not make sense. It makes more sense to do this: 

This will indent lines where chara is not equal to "Race n(%)"

if chara ne 'Race n(%)' then chara="   "||chara.                                                             

 

Ayooo1
Obsidian | Level 7

Thank you. It worked.

tarheel13
Rhodochrosite | Level 12

Great! Happy to have helped!

Cynthia_sas
SAS Super FREQ
Hi:
I know many report analysts use PROC REPORT and some use the newer Report Writing Interface. I featured 3 different ways in these papers: https://support.sas.com/resources/papers/proceedings/pdfs/sgf2008/173-2008.pdf and https://support.sas.com/resources/papers/proceedings16/SAS5762-2016.pdf . To do any kind of reporting, you usually need to get the data from both datasets into one file and then work from there. I think that Lisa Fine also shows PROC REPORT examples of this in her book: Proc Report by Example, in the SAS/RedShelf bookstore, here: https://redshelf.com/app/ecom/book/1878389/proc-report-by-example-1878389-9781612909134-lisa-fine .

Cynthia
Cynthia_sas
SAS Super FREQ

Hi:
Lisa has code for her book in the book. I have the code for my original paper on the support web site, for papers here: https://support.sas.com/rnd/papers/ and click for the 2008 Global Forum papers and then search for the title Creating Complex Reports. There's a link to a zip file and to the original paper.
Basically, with PROC REPORT, you create a helper variable that allows PROC REPORT to use the INDENT= style override to do the indent.
Cynthia

 

  This is not an exact demographic example, but it illustrates how to do an indent with a STYLE override. Notice how the data already has some "helper" variables created that allow the indent level to be controlled in the COMPUTE block. The helper variables can all be hidden with the NOPRINT option, they are just displayed here to illustrate how you would use helper variables to control the order of the groups, the rows within each group and the indent level for each row.

Cynthia_sas_0-1671735203626.png

 

Cynthia

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 10 replies
  • 2717 views
  • 4 likes
  • 4 in conversation