Date: Thu, 1 May 2008 15:09:37 -0400
Reply-To: msz03@albany.edu
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Mike Zdeb <msz03@ALBANY.EDU>
Subject: Re: call execute crashing
Content-Type: text/plain;charset=iso-8859-1
hi ... having done this before, it's neat to see other approaches ... this skips both CALL EXECUTE
and PROC SQL, but does use PROC DATASETS (as recommended by Richard) ... another idea,
* data set with ODD names;
data odd;
retain qq ww ee rr tt yy .;
stop;
run;
* put the ODD names into a data set;
title 'OLD NAMES AND LABELS';
proc contents data=odd out=oddc (keep=name);
ods select variables;
run;
* use a data step to write RENAME and LABEL statements;
filename r temp;
filename l temp;
data _null_;
set oddc;
file r;
put 'rename ' name '= indu' _n_ ';';
file l;
put 'label indu' _n_ '= ' name ';';
run;
*use PROC DATASETS to rename and label the variables with the old variable names;
proc datasets lib=work nolist;
modify odd;
%include r;
%include l;
quit;
title 'NEW NAMES AND LABELS';
proc contents data=odd;
ods select variables;
run;
and you do end up with ...
OLD NAMES AND LABELS
Alphabetic List of Variables and Attributes
# Variable Type Len
3 ee Num 8
1 qq Num 8
4 rr Num 8
5 tt Num 8
2 ww Num 8
6 yy Num 8
NEW NAMES AND LABELS
Alphabetic List of Variables and Attributes
# Variable Type Len Label
3 indu1 Num 8 ee
1 indu2 Num 8 qq
4 indu3 Num 8 rr
5 indu4 Num 8 tt
2 indu5 Num 8 ww
6 indu6 Num 8 yy
--
Mike Zdeb
U@Albany School of Public Health
One University Place
Rensselaer, New York 12144-3456
P/518-402-6479 F/630-604-1475
> dc353@hotmail.com wrote:
>> On May 1, 7:43 pm, rdevene...@WILDBLUE.NET ("Richard A. DeVenezia")
>> wrote:
>>> dc...@hotmail.com wrote:
>>>> Hi, the following code is NOT working and crashing my sas session:
>>>
>>>> data indu_04;
>>>> set indu_02 ;
>>>
>>>> call execute ("rename FOREST = indu1;");
>>>
>>>> run;
>>>
>>>> Forest is the old variable name.
>>>
>>>> If I just issue: rename forest = indu1 it works fine.
>>>
>>> CALL EXECUTE emits sas code that is to be placed on the execution
>>> stack for processing when the step has completed.
>>> If the emitted code contains macro, it will be evaluated to a certain
>>> extent.
>>>
>>> Thus you are telling SAS to issue a RENAME statement in open code
>>> after the DATA Step has completed.
>>>
>>> You should be seeing this in the log
>>> ==============
>>> ###### + rename FOREST = indu1;
>>> ------
>>> 180
>>>
>>> ERROR 180-322: Statement is not valid or it is used out of proper
>>> order. ==============
>>>
>>> The SAS session should not be crashing, in the sense of going
>>> buh-bye and returning to the desktop.
>>>
>>> Note: If you EXECUTEd data step source code prior to the RENAME,
>>> then it would not crash.
>>> data _null_;
>>> call execute ('data whatever; set indu_02;');
>>> call execute ('rename....;');
>>> call execute ('run;');
>>> run;
>>> But you do _NOT_ want to use this pattern of coding, do you?
>>>
>>> --
>>> Richard A. DeVeneziahttp://www.devenezia.com
>>
>> Thanks for all your help. I have 50 variables that have odd names. I
>> think I can get this to work now. The object was to replace the names
>> with INDU1 - INDU50 and have the old names used as labels. In the
>> data set the original vars are listed randomly so I have a second
>> dataset that maps the old names to the new names. It's confusing that
>> the simple things like changing variable names are so complicated.
>
> If you are running a DATA Step just to rename variables, it would be better
> to use Proc DATASETS to modify only the table header.
>
> Since you have only 50 variables, this can be easily accomplish through the
> use of a single macro variable whose value is computed in Proc SQL by
> matching table column names with data in your control table.
>
> ---------------------------------
> data foo;
> retain a b C D e f 100;
> run;
>
> data name_map;
> length old_name new_name $32;
> input old_name new_name;
> datalines;
> a Group
> b Region
> c Date
> d Age
> e Metric1
> f Metric2
> run;
>
>
> Proc SQL;
> reset noprint;
> select cats(old_name,'=',new_name)
> into
> :rename_list separated by ' '
> from
> DICTIONARY.COLUMNS as SYSDICT
> , WORK.NAME_MAP as MAP
> where
> libname = 'WORK' and memname='FOO'
> and upcase (MAP.old_name) = upcase(SYSDICT.name)
> ;
>
> %put NOTE: rename_list is (&rename_list.);
>
> proc datasets nolist lib=work;
> modify foo;
> rename &rename_list.;
> quit;
>
> %symdel rename_list;
> ---------------------------------
>
> Richard A. DeVenezia
> http://www.devenezia.com
>
>