Date: Fri, 24 Dec 2004 10:10:19 -0500
Reply-To: Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Subject: Re: Order of FIRST. / LAST. variables in PDV
so what's the objective?
Perhaps it is to clarify the items of a complex by-list.
Previously, I've used %let final_by = %scan( &by-list, -1 );
Now I can see its limitations where that %scan returns something
from a name-list or abbrev: or _character_ for example.
I couldn't care less about storage order or pdv order, but
can see the need to expand that by-list.
Here's my suggestion:
data ; *using default data<N> to avoid name contention;
set &data( keep= &COMPLICATED_BY_VARIABLE_LIST );
stop;
run;
%let syslast =%upcase( &syslast );
proc sql noprint;
select name into :by-names separated by ' '
from dictionary.columns
where libname = "%scan( &syslast,1,. )"
& memname = "%scan( &syslast,2,. )"
order by varnum ;
%let n_byVars = &sqlobs ;
drop table &syslast ;
quit;
Then you have a fully populated list of the expanded by-var list,
in &by-names, and a counter of the number of by vars in &n_byVars.
Hope this helps.
If you need to support option validVarName= Any type names, then
you'll need a delimiter in that "separated by ......" clause
and may need to quote the names.
It all depends on how far you wish to support generalisations....
Merry Christmas
Peter Crawford
Crawford Software Consultancy Limited
UK
>> -----Original Message-----
>> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On
>> Behalf Of m n
>> Sent: Thursday, December 23, 2004 4:13 PM
>> To: SAS-L@LISTSERV.UGA.EDU
>> Subject: Order of FIRST. / LAST. variables in PDV
>>
>> Dear SAS-L,
>>
>> Does anyone know if there is a (*documented*) guarantee that
>> the order of the FIRST./LAST. variables in the PDV will be
>> the same as the order of variables in the expanded by-variable list?
>>
>> For instance:
>>
>> data &OUT;
>> set &DATA;
>> by &COMPLICATED_BY_VARIABLE_LIST;
>>
>> array first[*] first: ;
>>
>> do I=1 to dim(first);
>> * Retrieve name minus 'FIRST.';
>> x = substr(vname(first[I]), 7);
>> put x=;
>> end;
>> run;
>>
>> Is there any guarantee that the FIRST. variable ordering will
>> line up with the expanded by-variable ordering (so that I can
>> expand the complicated variable list)?
>>
>> This works in my experiments, but I can't find documentation
>> about this, and so I hate to rely upon "seems to work" rather
>> than "guaranteed to work".
>>
>> Thanks for your help!
>>
>> Matt
>>
>> <ASIDE> The above code breaks if you have variables in the
>> data step that begin with 'First' (other than the 'First.'
>> variables). SAS does not allow First.:, unfortunately. </ASIDE>
>>
>>
>>
>>
>>
>> __________________________________
|