The SAS Output Delivery System and reporting techniques

How can i prefix the variable?

Reply
N/A
Posts: 0

How can i prefix the variable?

Hi,

I have on question.I have two data sets with same variable names,How to merge two data sets with diff names,without using reaname function .by using arrays how can do?
Dataset 1,

X Y
a 23
b 24

dataset2

X Y
x 234
s 123

output

x1 y1 x2 y2
a 23 x 234
b 24 s 123.
N/A
Posts: 0

Re: How can i prefix the variable?

why the restrictions ?
N/A
Posts: 0

Re: How can i prefix the variable?

Becase in our dataset there are 25 field names.
N/A
Posts: 0

Re: How can i prefix the variable?

since you want a common suffix, depending on the source data set, I don't understand why having many names causes the rename restriction, nor the suggestion of using an array. The "data dictionary" tables in a SAS environment, allow the names to be treated as data and stored for use in a macro variable, like[pre]
proc contents data= your.dataset1 noprint out= names1; run;
proc contents data= your.dataset2 noprint out= names2; run;
proc sql ;
select trim( name) !! '=' !! trim( name) !! '_1'
into :rename1 separated by ' '
from names1
where lowcase(name) ne "key_column_name"
;
select trim( name) !! '=' !! trim( name) !! '_2'
into :rename2 separated by ' '
from names2
where lowcase(name) ne "key_column_name"
;
quit;[/pre]
That prepares the rename information without you having to name any columns, except logical exclusions from renaming, like the key fields.
Use this rename information in your merge step, like[pre]
data merged_data ;
merge your.dataset1( rename= (&rename1))
your.dataset2( rename= (&rename2)) ;
by key_column_name ;
run;
[/pre]
So, is there some real reason to use arrays and avoid the rename processing ?

PeterC
Ask a Question
Discussion stats
  • 3 replies
  • 124 views
  • 0 likes
  • 1 in conversation