BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi All,

Please I am having trouble with the syntax for working with relational databases. I have two SAS files on the same CD with a one-to-many relationship and one common field (ID No).
Please I need help with with the code/command to read 'simultaneously' from both files/datasets.

Thanks.
3 REPLIES 3
DouglasMartin
Calcite | Level 5
Do you mean something more than doing a merge or SQL join?

data combined;
merge cd.file1 cd.file2;
by IDNo;
run;

If you like SQL you can do the equivalent in PROC SQL.
deleted_user
Not applicable
Thanks Douglas.
However, it appears I'm still not doing something right (I'm really new to SAS).
Additional info: The IDNo represents individual patients. Each patient in file1 has many test results in file2.

I am interested in analyzing the data to see, for instance, the mean value of the test results for each patient, etc.
Can you help me with the code please, starting from reading the files (my cd drive is 'D').

Thanks for the trouble.
DouglasMartin
Calcite | Level 5
If you're doing stats based just on the idno variable then you don't need to combine anything - just run proc means on the file2 dataset.

So, lets assume you want to display the name (presumably from file1) in place of idno, and do stats on result (presumably in file2).

I'm doing this off the top of my head, so there may be typos. I've included some other stats besides mean just to give you a better example.

libname cd "D:\";
data combined;
merge cd.file1 cd.file2;
by IDNo;
run;
proc means data=combined mean std median min max;
class name;
var result;
run;

If that's not enough explanation, you really need to consult the documentation.

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