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

Hello experts! I am trying to create 3 different data tables and sort them all by the different levels of smoking, with the respective titles being Smoking = Heavy Smoker, Smoking = Occasionally, and Smoking = Never. I need this to be in html output, sorted in descending order by patient, and also sorted by the different levels of smoking. When trying to write the titles, SAS seems to ignore these. Please help!

 

Here is my code:

data exercise1;
input Patient Weight Height Age BMI Smoking $ Asthma $;
cards;
14 167 70 65 23.9593878 never no
9 . 74 64 . never yes
4 165 65 25 27.4544379 occasionally no
2 152 67 60 23.8039652 heavy_smoker yes
13 161 70 77 23.0985714 occasionally yes
1 143 64 55 24.5432129 occasionally no
7 148 71 61 20.6395556 occasionally yes
11 281 69 45 41.4919135 heavy_smoker yes
5 220 70 58 31.5632653 occasionally no
6 182 64 26 31.2368164 never no
8 190 66 74 30.6634527 occasionally yes
12 . . 39 . occasionally yes
3 190 69 63 28.0550305 never no
15 148 67 53 23.1775451 never yes
10 152 65 61 25.2913609 never yes
;
proc sort;
by patient;
run;
proc sort;
by smoking;
run;
proc report data=exercise1;
title 'Smoking = Heavy Smoker';
where smoking = 'heavy_smoker';
run;
proc report data=exercise1;
title 'Smoking = Never';
where smoking='Never';
run;
proc report data=exercise1;
title 'Smoking = Occasionally';
where smoking='Occasionally';
footnote 'Data from Medical Records';
run;
proc print noobs;
var Patient Asthma Age BMI;
by <descending> patient;
run;
proc print noobs;
var Patient Asthma Age BMI;
by smoking;
run;
title;
 
I attached a picture of the result window
 
 
1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

By-group processing allows you to create a table per by group. Proc Report will then write a "title" per by-group on top of the table.

data exercise1;
  input Patient Weight Height Age BMI Smoking $ Asthma $;
  cards;
14 167 70 65 23.9593878 never no
9 . 74 64 . never yes
4 165 65 25 27.4544379 occasionally no
2 152 67 60 23.8039652 heavy_smoker yes
13 161 70 77 23.0985714 occasionally yes
1 143 64 55 24.5432129 occasionally no
7 148 71 61 20.6395556 occasionally yes
11 281 69 45 41.4919135 heavy_smoker yes
5 220 70 58 31.5632653 occasionally no
6 182 64 26 31.2368164 never no
8 190 66 74 30.6634527 occasionally yes
12 . . 39 . occasionally yes
3 190 69 63 28.0550305 never no
15 148 67 53 23.1775451 never yes
10 152 65 61 25.2913609 never yes
;

proc sort data=exercise1;
  by smoking Patient;
run;

ods _all_ close;
ods html5 body="%sysfunc(pathname(work))/excercise.htm";
title1 'Exercise 1';
proc report data=WORK.EXERCISE1 nowd;
  by Smoking;
  column Patient Asthma age bmi;
  define Patient /order=data;
quit;
title;
ods html5 close;
ods listing;

For the HTML output:

Eventually replace %sysfunc(pathname(work)) with the path where you want to store the HTML output.

This path needs to be accessible from where your SAS process executes (=NOT your local PC but the SAS Server; your local paths would only work if you've got SAS installed locally on your PC/Laptop). 

View solution in original post

2 REPLIES 2
Patrick
Opal | Level 21

By-group processing allows you to create a table per by group. Proc Report will then write a "title" per by-group on top of the table.

data exercise1;
  input Patient Weight Height Age BMI Smoking $ Asthma $;
  cards;
14 167 70 65 23.9593878 never no
9 . 74 64 . never yes
4 165 65 25 27.4544379 occasionally no
2 152 67 60 23.8039652 heavy_smoker yes
13 161 70 77 23.0985714 occasionally yes
1 143 64 55 24.5432129 occasionally no
7 148 71 61 20.6395556 occasionally yes
11 281 69 45 41.4919135 heavy_smoker yes
5 220 70 58 31.5632653 occasionally no
6 182 64 26 31.2368164 never no
8 190 66 74 30.6634527 occasionally yes
12 . . 39 . occasionally yes
3 190 69 63 28.0550305 never no
15 148 67 53 23.1775451 never yes
10 152 65 61 25.2913609 never yes
;

proc sort data=exercise1;
  by smoking Patient;
run;

ods _all_ close;
ods html5 body="%sysfunc(pathname(work))/excercise.htm";
title1 'Exercise 1';
proc report data=WORK.EXERCISE1 nowd;
  by Smoking;
  column Patient Asthma age bmi;
  define Patient /order=data;
quit;
title;
ods html5 close;
ods listing;

For the HTML output:

Eventually replace %sysfunc(pathname(work)) with the path where you want to store the HTML output.

This path needs to be accessible from where your SAS process executes (=NOT your local PC but the SAS Server; your local paths would only work if you've got SAS installed locally on your PC/Laptop). 

heatherjae15
Obsidian | Level 7

I need to make this table.  The variables are listed on the left.  I have done a proc freq, proc univariate, ttest, etc.  But I can't get them into a table like this.  Any help is appreciated.

Measure

Subject
(N=000)

Age (yrs)

00 ± 00 (00)

00 (00, 00)

[00,00]

Gender

 

    Male

00% (00/00)

    Female

00% (00/00)

Race

 

    American Indian / Alaska Native

00% (00/00)

    Asian

00% (00/00)

    Black / African American

00% (00/00)

    Native Hawaiian / Pacific Islander

00% (00/00)

    Caucasian

00% (00/00)

    Other

00% (00/00)

Ethnicity

 

    Hispanic or Latino

00% (00/00)

    Non-Hispanic or Latino

00% (00/00)

Height (cm)

00 ± 00 (00)

00 (00, 00)

[00,00]

Weight (kg)

00 ± 00 (00)

00 (00, 00)

[00,00]

BMI

00 ± 00 (00)

00 (00, 00)

[00,00]

Numbers are mean ± SD (N) / median (interquartile range) / [minimum, maximum] for continuous measures, and percent (count/N) for categorical measures.

 

 

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