DATA Step, Macro, Functions and more

Populating IDs from external file

Accepted Solution Solved
Reply
Regular Contributor
Posts: 243
Accepted Solution

Populating IDs from external file

[ Edited ]

Hi All,

I have some stored IDs that I need to assign to my observations. At the end I also want to disappear those IDs from that ID table and update that table.

 

 

DATA Have;
INPUT Course_ID$ age State$;
DATALINES;
ENG1 15 NY
Che1 10 NY
Eng2 15 CA
Phy2 11 PA
Che1 15 TX
;
RUN;

DATA ids;
INPUT slno;
DATALINES;
107
101
105
116
264
552
145
235
224
117
100
;
RUN;

PROC SORT DATA=ids;
BY slno;
RUN;

At the end I want the table 'Have' to be populated with slno from 'ids' table and lname it as want:

 

 

Want

slno   course_ID  Age State

100   ENG1         15     NY
101   Che1           10    NY
105   Eng2           15    CA
107   Phy2           11    PA
116   Che1           15    TX

 

 

Also, at the end ids table should stay with the remaining slno:

 

ids

slno

117

145

224

235

264

552

 

 

Thanks for your help in advance


Accepted Solutions
Solution
‎02-22-2018 10:48 AM
SAS Employee
Posts: 30

Re: Populating IDs from external file

Here's some code that I think will get what you're looking for!

 

DATA have ids(KEEP=slno);
	MERGE ids (IN=a)
	      have (IN=b);
	IF a AND b THEN output have;
	IF a AND not b THEN output ids;
RUN;

 

I've told the IDs to mash up horizontally with the data in have and only print to the have data set if there was a match. For cases where there was an ID but nothing to match it to, it was added back to ids and only the slno variable was preserved;

View solution in original post


All Replies
Solution
‎02-22-2018 10:48 AM
SAS Employee
Posts: 30

Re: Populating IDs from external file

Here's some code that I think will get what you're looking for!

 

DATA have ids(KEEP=slno);
	MERGE ids (IN=a)
	      have (IN=b);
	IF a AND b THEN output have;
	IF a AND not b THEN output ids;
RUN;

 

I've told the IDs to mash up horizontally with the data in have and only print to the have data set if there was a match. For cases where there was an ID but nothing to match it to, it was added back to ids and only the slno variable was preserved;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 70 views
  • 1 like
  • 2 in conversation