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
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;
Why do you think it's not working correctly? At a quick glance, it looks fine to me.
Tom
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
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
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.