Help using Base SAS procedures

SET STATEMENT

Accepted Solution Solved
Reply
Super Contributor
Posts: 1,040
Accepted Solution

SET STATEMENT

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


Accepted Solutions
Solution
‎10-03-2013 02:31 PM
Super User
Posts: 5,085

Re: SET STATEMENT

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


All Replies
Super Contributor
Posts: 333

Re: SET STATEMENT

Does the method matter? Data step vs sql?

EJ

Super Contributor
Posts: 1,040

Re: SET STATEMENT

Data step should be OK

Super Contributor
Posts: 333

Re: SET STATEMENT

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

EJ

Super Contributor
Posts: 1,040

Re: SET STATEMENT

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

Thanks

Super Contributor
Posts: 333

Re: SET STATEMENT

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

Super Contributor
Posts: 1,040

Re: SET STATEMENT

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;

Solution
‎10-03-2013 02:31 PM
Super User
Posts: 5,085

Re: SET STATEMENT

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.

Super Contributor
Posts: 1,040

Re: SET STATEMENT

Thanks Astounding.

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

Thanks so very much

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 264 views
  • 3 likes
  • 3 in conversation