Date: Sat, 10 Mar 2012 14:12:22 -0800
Reply-To: oloolo <dynamicpanel@yahoo.com>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: oloolo <dynamicpanel@YAHOO.COM>
Subject: Re: automatic array for unique variables
In-Reply-To: <CAEZCyss8161cJDGPweuqFA5KosrWZjSutVXmO2H+aRC_WhhCGw@mail.gmail.com>
Content-Type: text/plain; charset=iso-8859-1
Yes, I absolutely agree with you.
When working in SAS, working the way SAS should be working with.....
SAS Programming @ http://sas-programming.blogspot.com
________________________________
From: "Data _null_;" <iebupdte@gmail.com>
To: oloolo <dynamicpanel@yahoo.com>
Cc: SAS-L@listserv.uga.edu
Sent: Friday, March 2, 2012 9:58 AM
Subject: Re: automatic array for unique variables
This would be even more straight forward if GROUP were not already
dummy code you could use CLASS GROUP;
class group;
model id = Group*ss Group*al;
This way you don't have to even know how may groups there are.
On 3/2/12, oloolo <dynamicpanel@yahoo.com> wrote:
> or maybe something like :
>
> data testarray;
>
> input id group1 group2 group3 group4 ss al @@;
>
> cards;
> 1 1 0 0 0 301 1
> 2 0 1 0 0 302 2
> 3 0 0 1 0 303 3
> 4 0 0 0 1 304 4
> ;
> run;
>
> %macro wrap;
> proc glmmod data=testarray
> outdesign=want outparm=parmname
> noprint prefix=group ;
> model id = %do i=1 %to 4;
> Group&i *ss Group&i *al
> %end;;
> run;
>
> %mend;
> %wrap;
>
> On Thu, 1 Mar 2012 11:34:27 -0500, Paul Dorfman <sashole@BELLSOUTH.NET>
> wrote:
>
>>Jason,
>>
>>As Joe has already indicated, you will need to create the group*al and
>>group*ss variables at the compile time - no way of creating PDV entries at
>>the run time exists. However, you can use either metadata to find out how
>>many group* variables exist in your input file (as Joe has suggested) or a
>>short preliminary data step, for example:
>>
>>data _null_ ;
>> if 0 then set testarray ;
>> array grp group: ;
>> length arr $ 32767 ;
>> do vn = "ss", "al" ;
>> do over grp ;
>> arr = trimn (arr) || " " || cats ("group", _i_, vn) ;
>> end ;
>> end ;
>> call symputx ("arr", arr) ;
>> stop ;
>>run ;
>>
>>data testarray2 ;
>> set testarray ;
>> array new [2 , 4] &arr ;
>> _n_ = findc (cats (of group1-group4), "1") ;
>> new [1 , _n_] = ss ;
>> new [2 , _n_] = al ;
>>run ;
>>
>>Kind regards
>>------------
>>Paul Dorfman
>>Jax, FL
>>------------
>>
>>
>>On Wed, 29 Feb 2012 20:53:19 -0500, Jason Schoeneberger
>><jschoeneberger@CAROLINA.RR.COM> wrote:
>>
>>>Hi SASers,
>>>
>>>
>>>
>>>I'm wondering if someone has a quick way to code the following that is
> more
>>>'automated'. Here is some test data:
>>>
>>>
>>>
>>>data testarray;
>>>
>>> input id group1 group2 group3 group4 ss al @@;
>>>
>>> cards;
>>>
>>> 1 1 0 0 0 301 1
>>>
>>> 2 0 1 0 0 302 2
>>>
>>> 3 0 0 1 0 303 3
>>>
>>> 4 0 0 0 1 304 4
>>>
>>> ;
>>>
>>> run;
>>>
>>>
>>>
>>>And here is some code that works to show at least what I'm after.
>>>
>>>data testarray2;
>>>
>>> set testarray;
>>>
>>> array grp(*) group1 group2 group3 group4;
>>>
>>> array dvs(*) ss al;
>>>
>>> array new(*) group1ss group2ss group3ss group4ss;
>>>
>>> array new2(*) group1al group2al group3al group4al;
>>>
>>> do i = 1 to dim(grp);
>>>
>>> if grp[i]=1 then new[i]=ss;
>>>
>>> if grp[i]=1 then new2[i]=al;
>>>
>>> end;
>>>
>>> run;
>>>
>>>Is there a way to accomplish this without having to set up the two arrays
>>>named 'new' and 'new2' explicitly? Can new variable names be created from
>>>the concatenation of the elements of two other arrays.and can it be done
>>>even if the two input arrays (grp, dvs) are not of the same length?
>>>
>>>
>>>
>>>Or is this best handled in a macro? A colleague provided some code that
>>>accomplishes this in STATA.I've toyed around with it, but can't seem to
> get
>>>there. Any suggestions?
>>>
>>>
>>>
>>>Thanks,
>>>
>>>
>>>
>>>Jason
>
|