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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 4 replies
  • 797 views
  • 0 likes
  • 5 in conversation