BookmarkSubscribeRSS Feed
Rohan
Calcite | Level 5

Hello Friends,

I want to search if a observation (date) in data set B1 is in data set A1 or not.

If obv in A1 found then print "found" else append the observation of B1 into A1.

data a1;

input date_file $;

datalines;

24NOV2011

25NOV2011

26NOV2011

27NOV2011

28NOV2011

;

data b1;

input date_file $;

datalines;

26NOV2011

30NOV2011

;

I try to use PROC COMPARE but it's not giving desirable result. Please help me out.

Thanks

Rohan,

4 REPLIES 4
Haikuo
Onyx | Level 15

Assume they are both sorted, then we can have:

data a1;

merge a1(in=a) b1(in=b);

by date_file;

if a then output;

if a and b then put "Found=" date_file;

else if b and not a then output;

run;

Regards,

Haikuo

VijayNair
Calcite | Level 5

I Have to create datasets with sysmonth, sysmonth-1 & Sysmonth-2 as the names, how can i do that?

art297
Opal | Level 21

Vijay, Since your screen name is different than the original poster's name, I'd suggest that you start a new discussion, provide an example "have" data set and an example "want" dataset.

Linlin
Lapis Lazuli | Level 10

show off my newly acquired hash skills:

data a1;

input date_file $;

datalines;

24NOV2011

25NOV2011

26NOV2011

27NOV2011

28NOV2011

;

data b1;

input date_file $;

datalines;

26NOV2011

30NOV2011

;

data _null_;

  if _n_=1 then do;

  declare hash ha(dataset:'b1', ordered: 'yes');

    ha.definekey('date_file');

          ha.definedata('date_file');

          ha.definedone();

  end;

          set a1 ;

          rc=ha.find();

          if rc = 0 then put "Found=" date_file;

          else ha.add();

  ha.output(dataset:'ai_updated');

run;

Linlin

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1370 views
  • 0 likes
  • 5 in conversation