BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mlogan
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
GinaRepole
SAS Employee

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

1 REPLY 1
GinaRepole
SAS Employee

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;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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