BookmarkSubscribeRSS Feed
Yoko
Obsidian | Level 7

Hello, 

 

I want to create a table (please see an attached file) from the data set below: 

 

DATA data1;

input id age sex;
DATALINES;
1 1 1
2 2 2
3 3 2
4 1 2
5 1 1
6 3 1
7 1 1
8 2 2
9 1 1
;
run;

 

 

I can get numbers running multiple 'proc freq';

 

proc sort data=data1 out=data1_sort; by exp; run;

 

proc freq data=data1_sort;
table age sex;
run;

 

proc freq data=data1_sort;
table age;
by exp;
run;

 

proc freq data=data1_sort;
table sex;
by exp;
run;

 

But, I have to copy and paste the results. 

 

Is there a way(s) to get the table directly from the data set without copying and pasting results? 

 

Thank you, 

 

Yoko

11 REPLIES 11
novinosrin
Tourmaline | Level 20

can you paste the wanted output here rather than attachment?

 

Also,where is exp variable in data1?

Yoko
Obsidian | Level 7
Hello,


Sorry, I have to replace the data set with this one:

DATA data1;
input id age sex exp;
DATALINES;
1 1 1 0
2 2 2 1
3 3 2 0
4 1 2 1
5 1 1 1
6 3 1 1
7 1 1 0
8 2 2 0
9 1 1 0
;
run;


Also, the table looks like this;



All individuals

Exposure

Yes

No

Number

%

Number

%

Number

%

Age

1















2















3













Sex

1















2
















If you can not see the table well, please let me know.


Thank you,


Yoko



novinosrin
Tourmaline | Level 20

still no.

 

I ran your code to make a guess to figure out your expected output but my dumb brain isn't picking it

Yoko
Obsidian | Level 7
How about this? All individuals Exposure Yes No Number % Number % Number % Age 1 2 3 Sex 1 2
Yoko
Obsidian | Level 7
It’s getting messy. I’ll re-post my question.
Sorry about this..

Yoko


SuryaKiran
Meteorite | Level 14

Post any code or related comments in the right place. In the editor window you have a running man to add your code and {i} for adding any log info and so on.

Untitled.png

Thanks,
Suryakiran
Yoko
Obsidian | Level 7
Thank you for your comment.

It looks that posting codes is okay here, but I'm having a problem posting a table (.doc or .pdf).

Somebody was suggesting that this is a known issue for this site.


novinosrin
Tourmaline | Level 20

Ok, in that case, delete this one as to avoid duplication.

 

secondly, @SuryaKiran  has recommended the way to post in the right way

Yoko
Obsidian | Level 7
It looks that I cannot delete my post once I receive responses.

I'll try to find out how to show my table properly..

(my second attempt seemed to have failed.)


Thank you,


Yoko


ballardw
Super User

@Yoko wrote:
It looks that I cannot delete my post once I receive responses.

I'll try to find out how to show my table properly..

(my second attempt seemed to have failed.)


Thank you,


Yoko



Perhaps a screen capture, create image file as jpeg or png and use the PHOTOS icon here to upload the picture.

Astounding
PROC Star

This is a shot in the dark, since you still need to show more of what you need.  But this likely comes close to what you are asking for:

 

proc tabulate data=have missing;

class exp age sex;

tables exp age sex, n pctn;

run;

 

There are a lot of things to play with using PROC TABULATE, to control the format of the table.

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
  • 11 replies
  • 1064 views
  • 0 likes
  • 5 in conversation