I have a set of numbers that I need to collect the count for. Essentially, I need to perform :
proc sql;
create table lala&i as
select count(*)
from singlefamilyhht
where persons=4 and hinc<.8*(i)
or
persons=3 and hinc< .9*(.8*(i))
or
persons=2 and hinc< .8*(.8*(i))
or
persons=5 and hinc< 1.08*(.8*(i))
or
persons=6 and hinc< 1.16*(.8*(i))
group by puma1;
quit;
repeatedly for different medians (@i).
I wrote the following code:
%macro data;
%let median = {61000.00 68000.00 68400.00 88000.00 77400.00 84040.00 103000.00 65400.00 47800.00 75000.00 92000.00 80000.00 99000.00 64400.00 79300.00};
%do i = 61000 %to &median;
proc sql;
create table lala&i as
select count(*)
from singlefamilyhht
where persons=4 and hinc<.8*(i)
or
persons=3 and hinc< .9*(.8*(i))
or
persons=2 and hinc< .8*(.8*(i))
or
persons=5 and hinc< 1.08*(.8*(i))
or
persons=6 and hinc< 1.16*(.8*(i))
group by puma1;
quit;
%end;
%mend data;
My log is as follows:
Any recommendations?
I suspect you want something like this:
%macro loop;
%local i median medians;
%let medians = 61000.00 68000.00 68400.00 88000.00 77400.00 84040.00 103000.00 65400.00 47800.00 75000.00 92000.00 80000.00 99000.00 64400.00 79300.00;
%do i = 1 %to %sysfunc(countw(&medians,%str( )));
%let median=%scan(&medians,&i,%str( ));
create table LALA&i as
select count(*) as COUNT
,&median. as MEDIAN
,PUMA1
from SINGLEFAMILYHHT
where (PERSONS=2 and HINC < .80 .8 * &median)
or (PERSONS=3 and HINC < .90 * .8 * &median)
or (PERSONS=4 and HINC < 1.00 * .8 * &median)
or (PERSONS=5 and HINC < 1.08 * .8 * &median)
or (PERSONS=6 and HINC < 1.16 * .8 * &median)
group by PUMA1;
%end;
%mend ;
proc sql;
%loop;
quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.