Date: Thu, 28 Jul 2011 18:16:21 -0500
Reply-To: "Data _null_;" <iebupdte@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Data _null_;" <iebupdte@GMAIL.COM>
Subject: Re: Create Labels based off Variable Names
In-Reply-To: <CAL9q9Trs5=89EUuHDP0kAyF0efc94tyfV+H8uf=b-YV-4rbH3w@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
CALL EXECUTE is still just code gen.
Inefficient to read all the data just to modify the meta data.
On Thu, Jul 28, 2011 at 6:10 PM, Fareeza Khurshed <fkhurshed@gmail.com> wrote:
> I was trying to keep the problem simple and I did RTM that's how I found the
> IDLABEL option.
> I'll admit to not having reading it all though, by the time I'm old and grey
> I'll have read it all :)
>
> Another solution I got off-line that I'll post here as well, which is
> different than any others posted and does it in one data step.
>
> data x;
> PERIOD20111201=12;
> PERIOD20111202=45;
> run;
>
> data _null_;
> set x;
> array p period:;
> if _n_=1 then do;
> call execute('data x; set x; label ');
> do over p;
> call execute(vname(p)||'="FY'||
> substr(vname(p),9,2)||
> '/'||substr(vname(p),11,2)||' '||substr(vname(p),13,2)||'"');
> end;
> call execute('; run;');
> end;
> run;
>
> proc contents data=x;
> run;
>
> # Variable Type Len Label
>
> 1 PERIOD20111201 Num 8 FY11/12 01
> 2 PERIOD20111202 Num 8 FY11/12 02
>
>
>
>
>
> On Thu, Jul 28, 2011 at 3:57 PM, Data _null_; <iebupdte@gmail.com> wrote:
>>
>> Duh.
>>
>> Why didn't you say you created the data with PROC TRANSPOSE I thinks,
>> we would have suggested IDLABEL. Or better you RTM.
>>
>> On Thu, Jul 28, 2011 at 11:20 AM, Fareeza Khurshed <fkhurshed@gmail.com>
>> wrote:
>> > Thanks for all the solutions.
>> >
>> > I ended up using the IDLABEL line in an earlier proc transpose I was
>> > doing
>> > to get the labels in properly without macros.
>> >
>> > Thanks Again,
>> > Fareeza
>> >
>> > On Thu, Jul 28, 2011 at 9:10 AM, Bian, Haikuo <HBian@flqio.sdps.org>
>> > wrote:
>> >
>> >> I hope someone will simplify my code which is clumsy at best.
>> >>
>> >> With the off-line hints from data _null_, I have tried the following
>> >> multi-datasteps approach:
>> >> 1. Get the total number of variables into a macro variable: total
>> >> 2. Use array() and vname() to put variable names into series of macro
>> >> variable: a1-a3
>> >> 3. Use label statement to have the job done.
>> >>
>> >>
>> >> data have;
>> >> infile cards;
>> >> input PERIOD20111201 PERIOD20111202 PERIOD20111203;
>> >> cards;
>> >> 1 2 3
>> >> 4 5 6
>> >> ;
>> >> run;
>> >>
>> >> data _null_;
>> >> set have;
>> >> array v(*) PERIOD20111201--PERIOD20111203;
>> >> if _n_=1 then do;
>> >> call symput("total", dim(v));
>> >> end;
>> >> stop;
>> >> run;
>> >>
>> >> %macro labl;
>> >> %do i=1 %to &total;
>> >> data _null_;
>> >> set have;
>> >> array v(*) PERIOD20111201--PERIOD20111203;
>> >> if _n_=1 then do;
>> >> call symput("bb&i",cat('FY',
>> >> substr(vname(v(&i)),9,2),'/',substr(vname(v(&i)),11,2),'
>> >> ','P',substr(vname(v(&i)),13,2)));
>> >> call symput("a&i",vname(v(&i)));
>> >> end;
>> >> stop;
>> >> run;
>> >> %end;
>> >>
>> >> data want;
>> >> set have;
>> >> if _n_=1 then do;
>> >> %do i=1 %to &total;
>> >> label &&a&i = &&bb&i;
>> >> %end;
>> >> end;
>> >> run;
>> >> %mend labl;
>> >>
>> >> %labl
>> >>
>> >>
>> >> Regards,
>> >> Haikuo
>> >>
>> >>
>> >>
>> >> -----Original Message-----
>> >> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>> >> Fareeza Khurshed
>> >> Sent: Wednesday, July 27, 2011 12:47 PM
>> >> To: SAS-L@LISTSERV.UGA.EDU
>> >> Subject: Create Labels based off Variable Names
>> >>
>> >> Hi,
>> >>
>> >> I'm trying to create labels for certain variables based off the
>> >> variable
>> >> names.
>> >>
>> >> I have variables PERIOD20111201 PERIOD20111202 which translates to
>> >> FY11/12
>> >> P01 and FY11/12 P02.
>> >>
>> >> I want the labels to show like above (FY11/12 P01,FY11/12 P02 ) and
>> >> ideally
>> >> like to accomplish this in a datastep.
>> >>
>> >> Thanks,
>> >> Fareeza
>> >> -----------------------------------------
>> >> Email messages cannot be guaranteed to be secure or error-free as
>> >> transmitted information can be intercepted, corrupted, lost,
>> >> destroyed, arrive late or incomplete, or contain viruses. The
>> >> Centers for Medicare & Medicaid Services therefore does not accept
>> >> liability for any error or omissions in the contents of this
>> >> message, which arise as a result of email transmission.
>> >>
>> >> CONFIDENTIALITY NOTICE: This communication, including any
>> >> attachments, may contain confidential information and is intended
>> >> only for the individual or entity to which it is addressed. Any
>> >> review, dissemination, or copying of this communication by anyone
>> >> other than the intended recipient is strictly prohibited. If you
>> >> are not the intended recipient, please contact the sender by reply
>> >> email and delete and destroy all copies of the original message.
>> >>
>> >
>
>
|