BookmarkSubscribeRSS Feed
Neleh1811
Calcite | Level 5

Hi,

Can anyone please look through this code and tell me why the groups 3 and 4 are not working as I want then to???

thanks Smiley Happy

data order11_final;

set  order11_a;

if   Group =1 then do;

if Stream in ('A01' 'A02' 'A03')                             then do;  SEL_Nope='2122'; Outfile=1; end;

else

if Stream in ('B01' 'B02' 'B03')                             then do;  SEL_Nope='2123'; Outfile=1; end;

else

if Stream in ('E01')                                         then do;  SEL_Nope='2124'; Outfile=1; end;

else

if Stream in ('F02')                                         then do;  SEL_Nope='2125'; Outfile=1; end;

else

if Stream in ('G01')                                         then do;  SEL_Nope='2126'; Outfile=1; end;

end;

;/*correct*/



if   Group =2 then do;

else

if Stream in ('A01' 'A02' 'A03')                             then do;  SEL_Nope='2127'; Outfile=2; end;

else

if Stream in ('B01' 'B02' 'B03')                             then do;  SEL_Nope='2128'; Outfile=2; end;

else

if Stream in ('E01')                                         then do;  SEL_Nope='2129'; Outfile=2; end;

else

if Stream in ('F02')                                         then do;  SEL_Nope='2130'; Outfile=2; end;

else

if Stream in ('G01')                                         then do;  SEL_Nope='2131'; Outfile=2; end;

end;

;/* correct*/



if   Group =3 then do;


if _N_ <=17500                                               then do;  SEL_Nope='2137'; Outfile=3; end;

else

if _N_ <=35000                                               then do;  SEL_Nope='2145'; Outfile=5; end;

else

if _N_ <=52500                                               then do;  SEL_Nope='2146'; Outfile=6; end;

else

if Stream in ('A01' 'A02' 'A03')and buyer = 0 and Age <65    then do;  SEL_Nope='2132'; Outfile=3; end;

else

if Stream in ('B01' 'B02' 'B03')and buyer = 0 and Age <65    then do;  SEL_Nope='2133'; Outfile=3; end;

else

if Stream in ('E01')            and buyer = 0 and Age <65    then do;  SEL_Nope='2134'; Outfile=3; end;

else

if Stream in ('F01')                                         then do;  SEL_Nope='2135'; Outfile=3; end;

else

if Stream in ('N01')                                         then do;  SEL_Nope='2136'; Outfile=3; end;

end

;



if  Group =4 then do;


if _N_ <=17500                                               then do;  SEL_Nope='2144'; Outfile=4; end;

else

if Stream in ('A01' 'A02' 'A03') and buyer = 0 and Age >=65  then do;  SEL_Nope='2139'; Outfile=4; end;

else

if Stream in ('B01' 'B02' 'B03') and buyer = 0 and Age >=65  then do;  SEL_Nope='2140'; Outfile=4; end;

else

if Stream in ('E01')                                         then do;  SEL_Nope='2141'; Outfile=4; end;

else

if Stream in ('F01') and Age >=65                            then do;  SEL_Nope='2142'; Outfile=4; end;

else

if Stream in ('N01') and Age >=65                            then do;  SEL_Nope='2143'; Outfile=4; end;

end

;

run;

3 REPLIES 3
TomKari
Onyx | Level 15

Why do you think it's not working correctly? At a quick glance, it looks fine to me.

Tom

Neleh1811
Calcite | Level 5

Hi,

From groups 3 & 4 I want to output a few test and controls of 17500 but when I run it the volumes aren't 17500.

Any ideas?

Thanks

TomKari
Onyx | Level 15

Your response talks about outputting a few tests and controls, but your code will output one record for every input record.

So first of all, you should have the same number of output records as input records; that's what you're asking for.

Taking group 3 as an example:

any group 3 records in the first 17,500 records will be output with SEL_Nope='2137' and Outfile=3

the group 3 records between record 17,501 and 35,000 will be output with SEL_Nope='2145' and Outfile=5

same idea for group 3 records between record 35,001 and 52,500

Starting at any group 3 records on or after the 52,501st, your next set of if / then/ else statements will be processed, which will use the values of Stream, buyer, and Age to set SEL_Nope and Outfile. The records will then be output.

And finally, as these statements don't look exhaustive, any records that don't match any of the if criteria will have SEL_Nope and Outfile set to missing (.), and output.

Was this what you were trying to do?

Tom

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!

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