Date: Thu, 19 Feb 2009 17:41:32 -0600
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: Question on how to extend this to multiple variables
In-Reply-To: <09be01c992e6$86dd6740$832fa8c0@HP82083701405>
Content-Type: text/plain; charset=ISO-8859-1
I'm not entirely sure I understand precisely what you're doing (is this
effectively parsing a multiline column header into a single
label/description?), but what about this?
proc transpose data=test out=data_header_2;
var _all_;
run;
data data_master_header_2;
set data_header_2;
description = catx(' ',col1,col2,col3,col4);
variable = _name_;
keep description variable;
run;
-Joe
On Thu, Feb 19, 2009 at 5:05 PM, Mary <mlhoward@avalon.net> wrote:
> Or alternatively, a way to do this SQL without having
> to hard code in the variables seems to get me there:
>
> proc sql noprint;
> select trim(age_group) || ' ' into :age_group separated by ' '
> from test
> where trim(age_group) ^='';
> quit;
> %put &age_group;
>
> proc sql noprint;
> select trim(rs800292) || ' ' into :rs800292 separated by ' '
> from test
> where trim(rs800292) ^='';
> quit;
> %put &rs800292;
>
> proc sql noprint;
> select trim(rs2230199) || ' ' into :rs2230199 separated by ' '
> from test
> where trim(rs2230199) ^='';
> quit;
> %put &rs2230199;
>
>
> data data_master_header_2;
> age_group="&age_group";
> rs800292="&rs800292";
> rs2230199="&rs2230199";
> run;
>
>
> -Mary
>
>
> ----- Original Message -----
> From: Mary
> To: SAS-L@LISTSERV.UGA.EDU
> Sent: Thursday, February 19, 2009 4:44 PM
> Subject: Question on how to extend this to multiple variables
>
>
> Note this is a *question*, not an answer, though sometimes if I post a
> question I can think of an answer, but I'd appreciate it if anyone else
> would try to think of an answer as well!
>
> I've originally got an Excel file that has the description of the
> field in the same column as the field names and then the data.
> I've pulled those header columns, and put the variable names
> in the first row, and then I have saved it as text, and have
> data like the sample below.
>
> What I'm after is to write a program to create the data dictionary
> from this file, since it changes often along with the variable names
> and descriptions.
>
> I've got it going for one variable, as shown below, age_group.
>
> ****
> Question: How can I modify the code in data_master_header_2
> to aggregate for all variables (in my real data, I've got over 300,
> so I don't want to name variable names).
>
> Or other code that produces one record from the up to 4 possible
> records that is the concatenation of all 4 is what I'm after, kind
> of like one summary record except a concatenation of the records
> rather than a sum.
>
> *****
>
>
>
> data test;
> informat age_group $50. rs800292 $50. rs2230199 $50.;
> infile cards missover delimiter='^';
> input age_group rs800292 rs2230199;
> cards;
> ^CFH^ C3
> Age ^ IVS1/EX2^Ex2
> Group ^ ^rs2230199
> ^ rs800292^
> ;
> run;
>
> data data_master_header_2;
> informat age_group $40. prev_age_group $40.;
> format age_group $40. prev_age_group $40.;
> length age_group $ 40 prev_age_group $ 40;
> set test(firstobs=1 obs=4);
> retain age_group prev_age_group;
> if _N_=1 then
> do;
> age_group=age_group;
> prev_age_group=age_group;
> end;
> else
> do;
> age_group=trim(prev_age_group) || ' ' || trim(age_group);
> prev_age_group=age_group;
> end;
> if _N_ = 4 then output;
> keep age_group;
> run;
>
> data out2;
> informat variable_name $30. description $50.;
> set data_master_header_2;
> array vararray{*} age_group;
> do i=1 to dim(vararray);
> variable_name = vname(vararray[i]);
> description = vararray[i];
> output;
> end;
> keep variable_name description;
> run;
>
> -Mary
>
|