|
|||
|
On Fri, 30 Apr 2004 05:13:05 +1200, Dean Edwards <dean@DREAMNET.CO.NZ>
wrote: >"Thank you to all the people with your helpful replies to my earlier SAS problem. However "SAS Problem" is an extremely vague and uninformative Subject header. > > > >My first problem was to get the target points = (number of households for each area). > >and calculate the number of households for 26 areas that earn say $12,824 or less for example. This has been solved. > >. > >. I have resolved the statistical problem and it is just a coding issue problem now. Design and coding are not the same thing. If you leave out design you may get in some deep stuff. > > > >Here is my coding problem below: > > > >The problem below is I have to run this code 26 times separately to change the target=" " number which changes for each area. Target= "the number of households." > >THE CODING PROBLEM is that I have 26 target ranges to change. = (Area 1 has a target NUMBER=2,313 households for example). In my actual the full file would be 307,000 households broken into 26 areas multiply by 10 decile target income points = 260. > > > > > >My sample I have 26 households > >Area 1 = 13 records My target is 10 housholds for area 1 > >Area 2 = 13 records My target is 5 households for area2 > > > >This is the only thing I have to change in the program code below. > > > >Someone suggested a SAS macro. Is this the way to go to get target automated. Possibly, but not necessarily. The code below seems rather convoluted, and I'm not exactly sure of what it is doing. However, I suspect that non- macro looping and/or grouping can solve the problem. My usual rule is to avoid macro if there is a good alternative. > >I have 26 x 10 = target households to manually change. 260 changes to make. > >I am not a SAS expert. I would call myself barely competent. Anyone who tells me anything I have to go and get out the SAS manuals to read. > > > >I am just using a sample of 26 records but have a full file much larger than this > > > >data a; > > infile "H:\book1.txt" dlm='09'x dsd missover; Rather than pointing to a file which only you have, why not place the data inline (with a CARDS statement)? Runnable code is likely to get more attention. > > input area income count Target_Number; > >run; > > > >proc print; > >run; > > > >data b (keep= AREA Target_Number); > > set a; > >run; > > > > > >data boundary; > > set b; > > id+1; > >run; The last 3 DATA steps can easily be combined in one. > > > >* randomly allocate households to the lower decile group > > by taking an exact-sized random sample from the decile boundary group; > > > >data random (keep=readit target decile); > > target=10; * must change target number Here's the immediate problem. There is no semicolon at the end of the last line. Hence the following line is seen by the compiler as part of the comment. > > if _n_=1 then remains=totobs; > > > > do while (target>0 and readit<=totobs); > > readit+1; > > > > if ranuni(0) < target/remains then > > do; > > decile='01'; > > output; > > target=target-1; > > end; > > > > remains=remains-1; > > end; > > stop; > > set boundary point=_n_ nobs=totobs; So the SET is never executed. The only information taken from BOUNDARY is the number of observations. > > > >run; > > > >* reconstitute dataset with original variables; > >data ddd; > > set random; > > set boundary point=readit; > > > > > >proc print; > >run; > > >* followed by another data step to reset the remaining households (not selected in the random sample) to the higher decile group; This should be included in the problem statement. Its nature may be critical to the solution. > > > >Below is the sample 26 records > > Target_ > > Obs area income count Number > > > > 1 1 1 1231 0 > > 2 1 2 1561 0 > > 3 1 3 1681 0 > > 4 1 4 2421 10 Is this the same "10" that is to be embeeded in the TARGET= statement? If so, I don't understand. > > 5 1 5 3265 0 > > 6 1 6 6543 0 > > 7 1 7 3232 0 > > 8 1 8 7767 0 > > 9 1 9 4354 0 > > 10 1 10 3232 0 > > 11 1 11 8998 0 > > 12 1 12 4343 0 > > 13 1 13 3232 0 > > 14 2 1 111 0 > > 15 2 2 232 0 > > 16 2 3 567 0 > > 17 2 4 234 0 > > 18 2 5 666 5 > > 19 2 6 666 0 > > 20 2 7 789 0 > > 21 2 8 698 0 > > 22 2 9 541 0 > > 23 2 10 345 0 > > 24 2 11 344 0 > > 25 2 12 333 0 > > 26 2 13 678 0 > > > > > >The final output should look something like this below. The program has been run twice on area 1 and then area2 changing the target number from 10 to 5. I want to run the program once so it will output areas together > > Target_ > > Obs target decile area Number id > > > > 1 10 01 1 0 1 > > 2 9 01 1 0 2 > > 3 8 01 1 10 4 > > 4 7 01 1 0 5 > > 5 6 01 1 0 7 > > 6 5 01 1 0 8 > > 7 4 01 1 0 9 > > 8 3 01 1 0 10 > > 9 2 01 1 0 11 > > 10 1 01 1 0 13 > > Target_ > > Obs target decile area Number id > > > > 1 5 01 2 0 1 > > 2 4 01 2 0 2 > > 3 3 01 2 0 3 > > 4 2 01 2 5 5 > > 5 1 01 2 0 6 |
|
|
||||
|
||||
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Re: can anybody help this problem | Arthur Tabachneck | Newsgroup comp.soft-sys.sas | 0 | 02-18-2009 04:55 PM |
| Re: can anybody help this problem | Lewis Jordan | Newsgroup comp.soft-sys.sas | 0 | 02-18-2009 03:12 PM |
| Re: SAS/Intrnet image problem | edwken@googlemail.com | Newsgroup comp.soft-sys.sas | 0 | 04-30-2007 03:46 PM |
| Re: Macro Variable Problem (or should I say, coder problem) | toby dunn | Newsgroup comp.soft-sys.sas | 0 | 01-24-2007 07:38 PM |
| Re: Help on a grouping problem | Sigurd Hermansen | Newsgroup comp.soft-sys.sas | 0 | 02-15-2005 11:49 PM |