| Date: | Thu, 5 Apr 2007 16:21:46 -0400 |
| Reply-To: | "data _null_;" <datanull@GMAIL.COM> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | "data _null_;" <datanull@GMAIL.COM> |
| Subject: | Re: a question about data step |
|
| In-Reply-To: | <200704051931.l35J2Ewh000491@mailgw.cc.uga.edu> |
| Content-Type: | text/plain; charset=ISO-8859-1; format=flowed |
The recode is not that difficult. But the rename can be a problem
with that many variables. You could used an INFORMAT to read the
variable names and create a new name after the data are transposed.
This (flipflop) will also preserve the labels from the old variable
names. This program assumes all variable to be recode are numeric.
data work.rename;
infile cards eof=eof;
retain fmtname 'nv' type 'J' hlo 'UJ ';
input (start label) (:$32.);
start = upcase(start);
output;
return;
eof:
hlo = 'UJO';
start = ' ';
label = '_SAME_';
output;
stop;
cards;
height h
weight w
;;;;
run;
proc format cntlin=rename;
run;
proc transpose data=sashelp.class out=work.class;
by name sex;
var _numeric_;
label Height='Label for Height' weight='Weight label';
run;
data work.class;
set work.class;
attrib NewName length=$32;
NewName = input(_name_,$nv.);
if col1 in(.,1,14,62.8) /*extra values for this test data*/
then newVal=.;
else newVal=col1;
run;
proc transpose out=work.NewClass(drop=_name_);
by name sex;
var NewVal;
id NewName;
idlabel _label_;
run;
proc contents varnum;
proc print;
run;
On 4/5/07, Jane <program.sas@gmail.com> wrote:
> Hi All
>
> I had a question about the data step. I have a dataset, there have more than
> 100 variable. Since the data was from different source, the format is not
> consistent. (.,-1) are both as missing data. And, the variable name is very
> long. I need to change (.,-1) into "." and also change the variable name.
>
> I just know use the if...then... to do the changing for missing data like this:
>
> data want; set have;
> if abcdefghigk in (.,-1) then q1=.;
> else q1=abcefghigk;
> ........
> run;
>
> Does anyone have some efficient way to solve this problem? Hope I make the
> question clear.
>
> Thanks
> Jane
>
|