BookmarkSubscribeRSS Feed
lucazanotti
Fluorite | Level 6

Dear suppport, 

i hope you can help me in this. I have the following datasets ("info" and "score").

idid2facultyname surnamecourse
1xsciencemarkredmath
2ysciencelewisgreenmath
3zengjoshuayellowmath
3zengjoshuayellowenglish
    
     
     
     
     

score

idid2namesurnamecoursemark
1xmarkredmath5
3xmarkredenglish6
3zjoshuayellowmath7
3zjoshuayellowenglish8
4zjoshuayellowart9

 

 

What i would like to achieve is to insert some information in  "info" that recursively check based on some criteria if a specific entry on the "infor" is on score and if not append the new result in "infor". In detail it should check if Name and surname and id2 are in the score and only if the course is different append that line in "infor". My issue is that i have tried to do a data merge (and dropping one value) but unsuccessfull as the id field and faculty is wrong (not aligned with the infor or empty) .

The expected result should be like this:

idid2facultyname surnamecourse
1xsciencemarkredmath
2ysciencelewisgreenmath
3zengjoshuayellowmath
3zengjoshuayellowenglish
1xsciencemarkredenglish
3zengjoshuayellowart

with the last two observation inserted accordingly.

I wonder if is possible to loop through the dataset and check/compare (with if statements) and proceed to create the observation.

If you can post a link or guide me through into the right direction it would be amazing. 

Many thanks

Luca

3 REPLIES 3
Astounding
PROC Star

Sort and Merge can handle this with no problem.  If you ran into difficulties, you might have to add variables to the BY statement:

 

by id id2 name surname course;

 

It could take all five variables to determine match vs. mismatch.

novinosrin
Tourmaline | Level 20

proc sql;
create table want as
select distinct *
from
(select id	,id2	,	name ,	surname,	course from info
union 
select id	,id2	,	name ,	surname,	course from score);
quit;
lucazanotti
Fluorite | Level 6

Hi,

first of all many thanks for the reply.

I think i am going to use the first approach of merging and sorting across the variables as the UNION SQL cannot distinguish which rowe (giving the criteria described) need to be kept or not.

 

Luca

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 792 views
  • 2 likes
  • 3 in conversation