BookmarkSubscribeRSS Feed
deleted_user
Not applicable
I have created a job that will compare each variable between two different files (of the same format).

My problem right now is that I need to identify which file the data came from so that others looking at the reports can make sense of it. For instance,

File has the following fields:
INTN
FIRST
LAST
BIRTH_DT

I was thinking a simple way to distinguish where the value came from would be to have them called:
INTN_NEW or INTN_OLD
FIRST_NEW or INTN_OLD
LAST_NEW or LAST_OLD
BIRTH_DT_NEW or BIRTH_DT_OLD.

The variable names will change, depending on the files being read in so I can not hard code the variables and their new names. I was thinking a macro might work but then realized that it isn't really a repetitive action since I would be renaming all of the variables for every row at once. I have no idea where to start.

I tried searching these forums for past posts that might help (searched for RENAME, RENAMING, APPEND, ALTER VAR, and none of them had posts which really helped point me in a solid direction).
4 REPLIES 4
LinusH
Tourmaline | Level 20
I guess that you could use some macro programing by using information from DICTIONARY.COLUMNS so you could make your code dynamic. Have a look at proc sql select :into clause, and then use the result with rename data set option.

Good luck!

Linus
Data never sleeps
DanielSantos
Barite | Level 11
Hi.

Yes, DICTIONARY.COLUMNS or PROC CONTENTS with output to a dataset.

Next, you just need to load some macro variables with the input of the DICTIONARY.COLUMS/output from PROC CONTENTS and sufix them with _NEW / _OLD.

For examples:

proc contents data = WORK.INFILE out = WORK._CONTENTS noprint;
run;

* cats is just use for text trimming;
data _null_;
set WORK._CONTENTS end = _EOF; /* _EOF = 1 when end of file */

/* create VARX_NEW and VARX_OLD macro vars */
/* _N_ is the current observation number, NAME is the variable name */
call symput(cats('VAR',put(_N_,best.),'_NEW'),cats(NAME,'_NEW'));
call symput(cats('VAR',put(_N_,best.),'_OLD'),cats(NAME,'_OLD'));

/* if end of file store VAR_COUNT as total number of variables */
if _EOF then call symput('VAR_COUNT',cats(put(_N_,best.)));

run;

then you will be able to use in your code:

&VAR1_NEW
&VAR1_OLD
...

being &VAR_COUNT the total variable count.

Hope it helps.

Greetings from Portugal.

Daniel Santos at www.cgd.pt
deleted_user
Not applicable
Daniel,

That worked like a charm! Once I used that...I simply had to rename the variables like this...

PROC DATASETS;
MODIFY WORK.INFFILE;

RENAME VAR1 = &VAR1_NEW;
RENAME VAR2 = &VAR2_NEW;
RENAME VAR3 = &VAR3_NEW;

RUN;
data_null__
Jade | Level 19
> I have created a job that will compare each variable
> between two different files (of the same format).

That sounds like PROC COMPARE. No need to fiddle changing anything.

If you only want to COMPARE variable names, attributes, and location use OBS=0;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1527 views
  • 0 likes
  • 4 in conversation