LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (August 2005, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Fri, 26 Aug 2005 11:59:48 +0300
Reply-To:   Vladislav <Vladislav.Moltchanov@KTL.FI>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   Vladislav <Vladislav.Moltchanov@KTL.FI>
Organization:   KTL (Kansanterveyslaitos)
Subject:   Re: thousands of numeric variables convert to charector variables
Comments:   To: sas-l@uga.edu
In-Reply-To:   <20050826004720.34164.qmail@web30902.mail.mud.yahoo.com>
Content-Type:   text/plain; charset=us-ascii; format=flowed

I guess, if I know the final purpose of the data manipulation you are doing, I would advise you some more practical way. However here is some practical was to do exactly what you have specified. You should use Proc option with out= option to generate several macro variables, then to use them in the data step, performing transformation .

Here is the code, which proved to work in Open/Vms SAS8.2

/* ~ bType SAS ~ bName TMP010.SAS ~ bCategory Module ~ bCreated 26-AUG-2005 ~ bBy V.Moltchanov ~ bPurpose converting all numerical variables to character ones ~ bInput &dsin - name of input SAS data set ~ bOutput &dsout- name of resulting SAS data set ~ bControl &pref - prefix for intermediate working names ~ bDetails temporary text files _rena_to.txt and _rena_fro.txt in working version are to be deleted automatically. ~ LUsage

~> */

libname cvd "RISK_ROOT:[FR_PR.DM_CVD.WRK_KATOH]"; %let dsin=cvd.CHD_ALL; %let pref=___; %let dsout=d._dsout;

proc contents noprint out=cont(keep=name type length label format formatl formatd npos) data=&dsin; run; proc sort; by type;

*generating &rena_to &nvar_num &nvar_all; data _null_; file '_rena_to.txt'; set cont end=eof; length z $ 200; if _N_=1 then put '%let rena_to='; z=trim(name)!!"=&pref.x" !! left(put(_N_,6.)); nvar_num+(type=1); *count of numerical variables; nvar_all+1; *count of all variables ; if eof then do; put z ';'; call symput('nvar_num', left(put(nvar_num,6.))); call symput('nvar_all', left(put(nvar_all,3.))); end; else put z; run; %inc '_rena_to.txt'; run; *at this point macro var rena_to nvar_num and nvar_all are ready; %put &nvar_num &nvar_all;

*generating &rena_fro; data _null_; file '_rena_fro.txt'; set cont end=eof; length z $ 200; if _N_=1 then put '%let rena_fro='; if type=1 then z= "&pref.s" !! left(put(_N_,6.))!!"="!! trim(name); else z= "&pref.x" !! left(put(_N_,6.))!!"="!! trim(name);

if eof then put z ';'; else put z; run; %inc '_rena_fro.txt';

*at this point macro var rena_fro is ready; ruN;

data &dsout (rename=(&rena_fro)); length &pref.s1- &pref.s&nvar_num $ 20; set &dsin(rename=(&rena_to)); array x &pref.x1- &pref.x&nvar_num; array s &pref.s1- &pref.s&nvar_num; do i=1 to &nvar_num; s[i]= put(x[i],best.); end; drop i &pref.x1- &pref.x&nvar_num; run; Proc contents;run;

> Hi All, > > I know how to convert limited numeric variables to > charector variables. But I could not think of a easy > way to convert thousands of numeric variables to > charector variables. >


Back to: Top of message | Previous page | Main SAS-L page