BookmarkSubscribeRSS Feed
aether
Fluorite | Level 6

How to create two tables in SAS from one database. Thanks in advance.

 

The question goes like this: "Create a set that contains all incident variables (non-cumulative cases): ANGINA, HOSPMI, HYPERTEN, MI_FCHD, STROKE. Create a sum that includes incidents. Conditionally output the data to two different SAS tables: one that has subjects with 1 or more incidents and one with subjects with no incidents." 

 

What is the principle to summarize the data in order to derive two tables from them: "without incidents" and "1 or more inc."

 

UPD. How to summarize this data horizontally to get the second table "No incidents (0)" ?

 

Снимок.PNG

7 REPLIES 7
Reeza
Super User

This depends a lot on your data structure and how you can identify records. 

 

You can direct output to two different data sets relatively easily.

 

data females males other; * list of data sets that will be created;

set sashelp.class; *input data;

*conditionally assign to different output data sets;
if sex = 'F' then output females;
else if sex = 'M' then output males;
else output Other;

run;

 

 


@aether wrote:

How to create two tables in SAS from one database. Thanks in advance.

 

The question goes like this: "Create a set that contains all incident variables (non-cumulative cases): ANGINA, HOSPMI, HYPERTEN, MI_FCHD, STROKE. Create a sum that includes incidents. Conditionally output the data to two different SAS tables: one that has subjects with 1 or more incidents and one with subjects with no incidents." 

 

What is the principle to summarize the data in order to derive two tables from them: "without incidents" and "1 or more inc."

 

 

 



 

VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

Please post 2 sets of sample data showing what you have and what you want.

Reeza
Super User
1. How do you define "no incidents"? What is the logic?
2. Have you tried to modify my code to implement the logic from #1.
aether
Fluorite | Level 6
1. "No incidents" = 0 in whole line. 2. Yes.
Reeza
Super User

Show your code please.

 


@aether wrote:
1. "No incidents" = 0 in whole line. 2. Yes.

 

aether
Fluorite | Level 6
data dataset;
      infile '\path\dataset.dat' FIRSTOBS = 2 DSD;
      input /*other variables*/ RANDID ANGINA HOSPMI MI_FCHD STROKE HYPERTEN;
 	  keep RANDID ANGINA HOSPMI MI_FCHD HYPERTEN STROKE;
run;
ods html close;
ods html file = "\path\output.html";

/*here, it seems to me, there should be a horizontal summation by RANDID*/

data NOINC INC;
	set work.dataset;
	if /*sum*/ = 0 then output NOINC;
	else if /*sum*/ = >1 then output INC;
run;
Reeza
Super User
sum(<list of variables go here>)

You're pretty close, just add in your list of variables then.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 7 replies
  • 5058 views
  • 0 likes
  • 3 in conversation