DATA Step, Macro, Functions and more

DO loop Help

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

DO loop Help

Hello Everyone,

 

I cannot seem to get my code to generate the data in the EarningRangesLow variable beyond $1. Any help is appreciated. Here is my code:

 

data Chesapeake4 ;
infile '/home/sherstewart0/my_content/Chesapeake4.csv' dsd firstobs=3 delimiter=',';
length EarningRangesLow $ 100 EarningRangesHigh $ 100;
format MaleWorkedFT best32.;
format FemaleWorkedFT best32.;

do EarningRangesLow ="$1 "
,"$2,500 "
,"$5,000"
,"$7,500"
,"$10,000 "
,"$12,500 "
,"$15,000 "
,"$17,500"
,"$20,000 "
,"$22,500 "
,"$25,000 "
,"$30,000"
,"$35,000"
,"$40,000"
,"$45,000 "
,"$50,000 "
,"$55,000"
,"$65,000 "
,"$75,000"
,"$100,000 ";


do EarningRangesHigh="$2,499 "
,"$4,999 "
,"$7,4999"
,"$9,999"
,"$12,499"
,"$14,999 "
,"$17,499 "
,"$19,999"
,"$22,499 "
,"$24,999"
,"$29,999 "
,"$34,999"
,"$39,999"
,"$44,999"
,"$49,999 "
,"$54,999"
,"$64,999"
,"$74,999"
,"$99,999"
,"$149,999 "
;

input skip $ MaleWorkedFT FemaleWorkedFT ;
drop skip;

output;

end;
end;

run;


Accepted Solutions
Solution
‎08-16-2017 01:22 PM
Esteemed Advisor
Posts: 5,399

Re: DO loop Help

You seem to need something like this:

data Chesapeake4;
array a(20) $10 _temporary_ (
"$1 "
,"$2,500 "
,"$5,000"
,"$7,500"
,"$10,000 "
,"$12,500 "
,"$15,000 "
,"$17,500"
,"$20,000 "
,"$22,500 "
,"$25,000 "
,"$30,000"
,"$35,000"
,"$40,000"
,"$45,000 "
,"$50,000 "
,"$55,000"
,"$65,000 "
,"$75,000"
,"$100,000");
array b(20) $10 _temporary_ (
"$2,499 "
,"$4,999 "
,"$7,4999"
,"$9,999"
,"$12,499"
,"$14,999 "
,"$17,499 "
,"$19,999"
,"$22,499 "
,"$24,999"
,"$29,999 "
,"$34,999"
,"$39,999"
,"$44,999"
,"$49,999 "
,"$54,999"
,"$64,999"
,"$74,999"
,"$99,999"
,"$149,999");
infile '/home/sherstewart0/my_content/Chesapeake4.csv' dsd firstobs=3 delimiter=',';
do i = 1 to dim(a);
    EarningRangesLow = a{i};
    EarningRangesHigh = b{i};
    input skip $ MaleWorkedFT FemaleWorkedFT ;
    output;
    end; 
drop i skip;
run;
PG

View solution in original post


All Replies
PROC Star
Posts: 1,328

Re: DO loop Help

[ Edited ]

Is it just for fun: You can play with something like this

 

 

 data want;

 do _EarningRangesLow=1 to 100000 by 2500;

 EarningRangesLow=put(_EarningRangesLow,dollar10. -l);

 if _EarningRangesLow=1 then  _EarningRangesHigh=2499;

 else _EarningRangesHigh=_EarningRangesHigh+2500;

 EarningRangesHigh=put(_EarningRangesHigh,dollar10. -l);

  output;

 if _EarningRangesLow=1 then _EarningRangesLow=0;

end;

drop _:;

run;

 

New Contributor
Posts: 3

Re: DO loop Help

Posted in reply to novinosrin

Thanks, I will try playing with that. So many different ways to approach this. It can be frustrating... 

Super User
Posts: 13,046

Re: DO loop Help

How many records are in your CSV file? If it is fewer than 20 you run out of lines to input while still in the first loop for the EarningRangesLow.

 

Are attempting generate someth that is supposed to create something like:

 

MaleworkedFt FemaleWorkedFt       1 2499

MaleworkedFt FemaleWorkedFt 2500 4999

 

I suspect that FORMATS will do what you want but you'd have to describe what this data is going to be used for.

Solution
‎08-16-2017 01:22 PM
Esteemed Advisor
Posts: 5,399

Re: DO loop Help

You seem to need something like this:

data Chesapeake4;
array a(20) $10 _temporary_ (
"$1 "
,"$2,500 "
,"$5,000"
,"$7,500"
,"$10,000 "
,"$12,500 "
,"$15,000 "
,"$17,500"
,"$20,000 "
,"$22,500 "
,"$25,000 "
,"$30,000"
,"$35,000"
,"$40,000"
,"$45,000 "
,"$50,000 "
,"$55,000"
,"$65,000 "
,"$75,000"
,"$100,000");
array b(20) $10 _temporary_ (
"$2,499 "
,"$4,999 "
,"$7,4999"
,"$9,999"
,"$12,499"
,"$14,999 "
,"$17,499 "
,"$19,999"
,"$22,499 "
,"$24,999"
,"$29,999 "
,"$34,999"
,"$39,999"
,"$44,999"
,"$49,999 "
,"$54,999"
,"$64,999"
,"$74,999"
,"$99,999"
,"$149,999");
infile '/home/sherstewart0/my_content/Chesapeake4.csv' dsd firstobs=3 delimiter=',';
do i = 1 to dim(a);
    EarningRangesLow = a{i};
    EarningRangesHigh = b{i};
    input skip $ MaleWorkedFT FemaleWorkedFT ;
    output;
    end; 
drop i skip;
run;
PG
New Contributor
Posts: 3

Re: DO loop Help

Thanks that worked like a charm...! 

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 177 views
  • 0 likes
  • 4 in conversation