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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 11 replies
  • 1461 views
  • 0 likes
  • 5 in conversation