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

Table: Person

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| PersonId    | int     |
| FirstName   | varchar |
| LastName    | varchar |
+-------------+---------+
PersonId is the primary key column for this table.

Table: Address

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| AddressId   | int     |
| PersonId    | int     |
| City        | varchar |
| State       | varchar |
+-------------+---------+
AddressId is the primary key column for this table.

 

Use data step for a report that provides the following information for each person in the Person table, regardless if there is an address for each of those people:

FirstName, LastName, City, State

 

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Do something like this (just made some data up)

 

data Person;
input PersonID FirstName $ LastName $;
datalines;
1 Peter Smith
2 Otto Burch
3 Paul Johnson
4 William Jones
5 Allan Brown
;

data Address;
input AddressID PersonID City $ State $20.;
datalines;
72 1 Houston Texas
44 3 Miami Florida
87 5 Seattle Washington
;

proc sort data=Person; by PersonID; run;
proc sort data=Address; by PersonID; run;

data want(drop=PersonID AddressID);
   merge Person(in=p) Address;
   by PersonID;
   if p;
run;

View solution in original post

1 REPLY 1
PeterClemmensen
Tourmaline | Level 20

Do something like this (just made some data up)

 

data Person;
input PersonID FirstName $ LastName $;
datalines;
1 Peter Smith
2 Otto Burch
3 Paul Johnson
4 William Jones
5 Allan Brown
;

data Address;
input AddressID PersonID City $ State $20.;
datalines;
72 1 Houston Texas
44 3 Miami Florida
87 5 Seattle Washington
;

proc sort data=Person; by PersonID; run;
proc sort data=Address; by PersonID; run;

data want(drop=PersonID AddressID);
   merge Person(in=p) Address;
   by PersonID;
   if p;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1 reply
  • 2023 views
  • 1 like
  • 2 in conversation