BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
robertrao
Quartz | Level 8

Hi ,

How can i combine these two datasets into a single step but giving me the same OUTPUT as when i do them seperately

data want1(keep=flag ID PLACEMENT);
set have(keep=ID  PLACEMENT);
if ("&start"D <=PLACEMENT <= "&end"D)
flag="IN";
run;

data want2(keep=flag ID REMOVAL);
set have(keep=ID REMOVAL);
if ("&start"D <=REMOVAL <= "&end"D)
flag="OUT";
run;

Finally i want to set the PLACEMENT and REMOVAL under ONE variable and flag will be the identifier

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The smaller issue is the use of VALUE vs. FLO_MEAS_ID.  That might just be a typo in posting your program.

The bigger issue is that no observations satisfy the IF conditions.  You'll have to inspect your data to find out why.  A likely possibility is that REMOVAL and PLACEMENT contain datetime values, rather than date values.  If that's the case, you would have to apply the DATEPART function to them in order to compare them to dates.

Good luck.

View solution in original post

8 REPLIES 8
esjackso
Quartz | Level 8

Does the method matter? Data step vs sql?

EJ

robertrao
Quartz | Level 8

Data step should be OK

esjackso
Quartz | Level 8

I guess I should have also asked whether you mean you want the data appended or merged ... I wasnt clear from your description.

EJ

robertrao
Quartz | Level 8

Yes. The Placement and REMOVAL data needs to be appended under a single variable

Thanks

esjackso
Quartz | Level 8

I dont have a easy way to test this but something like the following should work (may have to play with the variable name in the where statements and you might have to break the where into two separate statements ... ie .... and placement <= "&end"D 😞

data want (keep=flag id onevar);

     length flag $3;

     set have (in=a rename=(placement=onevar) where=("&start"D <=PLACEMENT <= "&end"D))

          have (in=b rename=(removal=onevar) where=("&start"D <=removal <= "&end"D));

     if a then flag = "IN";

     if b then flag = "OUT";

run;

    

Hopefully this at least puts you on the right track.

EJ

robertrao
Quartz | Level 8

Hi,

I am doing like this and both my output datasets have zero records..

i am not able to figure out where i am going wrong?

data out(keep=flag id REMOVAL)

IN(keep=flag id  PLACEMENT);

set have(keep=id PLACEMENT REMOVAL value);

IF ("&start"D <= REMOVAL <= "&end"D) and value in('270' '2701' '2703' '27033') THEN DO;
FLAG="OUT";

OUTPUT out;
END;

IF ("&start"D <= PLACEMENT<= "&end"D) and FLO_MEAS_ID in('270' '2701' '2703' '27033') THEN DO;
FLAG="IN";

OUTPUT IN;
END;
run;

Astounding
PROC Star

The smaller issue is the use of VALUE vs. FLO_MEAS_ID.  That might just be a typo in posting your program.

The bigger issue is that no observations satisfy the IF conditions.  You'll have to inspect your data to find out why.  A likely possibility is that REMOVAL and PLACEMENT contain datetime values, rather than date values.  If that's the case, you would have to apply the DATEPART function to them in order to compare them to dates.

Good luck.

robertrao
Quartz | Level 8

Thanks Astounding.

I forgot to put the datepart. and as u mentioned they are datetime values..

Thanks so very much

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 8 replies
  • 971 views
  • 3 likes
  • 3 in conversation