BookmarkSubscribeRSS Feed
Florent
Quartz | Level 8
Hello,

Maybe you'll find this question very stupid but how can I compare values of a dataset's variable with all values of another dataset's variable ? This has to be done in a data step and not by using proc sql. Using two different set statements with a loop on the second one could be the solution or it's more simple ?

In fact if I found the value (which is a date) of the first dataset's variable in the second one, then I have to change the value of another variable from the first dataset ...

I hope this is more or less clear 😕

Thank you all,
Florent
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
Hi,
I'm just having a hard time visualizing how your data are structured or what you need to do. For example...if the data looked like this:
[pre]
data want;
infile datalines;
input code $ datewant : mmddyy10.;
return;
datalines;
code1 11/15/1950
code2 06/30/1949
;
run;

data search;
infile datalines;
input name $ date1 : mmddyy10. date2 : mmddyy10.;
return;
datalines;
lucy 12/05/1951 01/15/1953
ricky 11/15/1950 12/05/1951
fred 12/01/1948 11/15/1950
ethel 06/30/1949 08/12/1952
;
run;

ods listing ;
proc print data=want;
title 'want these';
format datewant mmddyy10.;
run;

proc print data=search;
title 'search here';
format date1 date2 mmddyy10.;
run;

[/pre]

Are you saying that you would check every date field on every obs in the 'Search' dataset to see if DATEWANT was found in either DATE1 or DATE2 ??? Is there a way to fabricate some test data that illustrates your problem a bit better???

Given the above data, I'd be very tempted to use a FORMAT for a lookup, assuming that the dates to lookup was a reasonable sized list.
[pre]

proc format;
value wantdate '15Nov1950'd = 'y'
'30Jun1949'd = 'y'
other='n';
run;

data search;
infile datalines;
input name $ date1 : mmddyy10. date2 : mmddyy10.;
ckdate1 = put(date1,wantdate.);
ckdate2 = put(date2,wantdate.);
return;
datalines;
lucy 12/05/1951 01/15/1953
ricky 11/15/1950 12/05/1951
fred 12/01/1948 11/15/1950
ethel 06/30/1949 08/12/1952
;
run;
[/pre]
And then the proc print of the above file would look like this (if you selected where ckdate1 = 'y' or ckdate2 = 'y'):
[pre]
Obs name date1 date2 ckdate1 ckdate2

2 ricky 11/15/1950 12/05/1951 y n
3 fred 12/01/1948 11/15/1950 n y
4 ethel 06/30/1949 08/12/1952 y n

[/pre]

There are lots of ways to make this automated using SAS to create a format from the "want" data set and using SAS macro variables/programs, but there's no point going farther down this road if your data is significantly different.

cynthia
Florent
Quartz | Level 8
Hi,

Thank you for your answer. It was a really interesting way to compare variables coming from 2 different datasets.

In fact I had to compare a date with another one (test if greater or not) and my problem was that I had to use it within a macro called in a data step. After a deeper analysis with a colleague, it appeared that the second dataset's dates were just holidays' references so I generated macro variables instead of using a dataset.

So the problem is solved 🙂

Thanks again for your answer,

Florent

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!

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
  • 2 replies
  • 1007 views
  • 0 likes
  • 2 in conversation