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
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;
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;
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!
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.