A Data Science Central Community
Please may I kindly seek your input in solving a problem in SAS. I want this done asap, hope someone can response on time.
Essentially, I want to group a variable in different ranges, with incremental value of 5000. So, the iteration, if done manually, will take about 20,000 entries and thus I am trying to adopt a clever way to automate this. I am sure either some do loops; array or iterative do- statement can do this.
Here is an example:
if 5000 <= totprice <= 10000 then vband=1;
else if 10000 < totprice <= 15000 then vband =2;
else if 15000 < totprice <= 20000 then vband =3;
else if totprice > 20000 then vband =4;
proc format ;
In the end, I will proc tabulate my table and the output will come up as formatted above with other stuff.
Any help will be appreciated.
Do you know how to write a macro?
Something along these lines:
if missing(totprice) then vband= .;
else if totprice<= 0 then vband= 0;
%do i = 1 %to 20000;
else if totprice<= %eval(&i. * 5000) then vband= &i.;
else vband = 20001;
Many thanks for your prompt response. I did tried to reply immediately but to no avail.
I have less expertise knowledge about macros but I quite understand the logic of your suggested code. However, it doesn't seem to work. When I copied & pasted it and do the obvious changes with data, some of the key functions aren't highlighted. Pls what am i doing wrong? Pls i will appreciate if you kindly provide more insight.
I look forward to hearing from you. Thanks a million!