After importing my CSV data with
GETNAMES = NO
, I have 59 columns, named VAR1, VAR2. . . VAR59 My first line contains the names that I want for the new variable, but they need to remove special characters and change the spaces to spaces because the SAS does not like spaces in variable names. This is the array I used for that piece: data data 1; Set stats (first obz = 7); ARRAY VAR (59) VAR1-VAR59; IF _N_ = 1 DO DO; DO I = 1 to 59; VAR [I] = COMPRESS (translation (trim (ver [ii]), '_', ''), '? ()'); Put VAR [I] =; End; End; Drop Drop; Run;
It was working perfectly, but now I have to take this new row to new variable names. I tried a similar array to do this:
data data 2; SET DATA1; ARRAY V (59) VAR1-VAR59; DO I = 1 to 59; IF _N_ = 1 AND V [I] NE "" Then Call Simut ("Nudem", V [I]); Rename VAR [I] = & amp; NEWNAME; End; Drop Drop; Run;
It only names VAR59 because [i]
and & amp; NEWNAME is not related to
, and it is still not working quite right after any manipulation any suggestions for running a variable? Your primary problem is that you use the macro variable in the data phase that you created. You can not do that, you are also trying to make statements to rename in the data phase; Before the data phase is compiled, you have to define rename
, with other identical statements ( keep
, drop
).
You have to type elsewhere - either in a text file, a macro variable, whatever - with this information. For example:
filename renamef temp; Data_null_; Set myfile (obs = 1); Rename the file; Array type [5 9]; _ _ = 1 for slow (war); [Your code to clean it]; Strut = cat ("rename", woman (var [_i]), '=', var [_i], ';'); Put the strip; End; Run; Want data; Set myfile (firstobs = 2); % Include renamef; Run;
There are many other examples on the site and on the web, the word "processing" is the word for it.