BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NewUsrStat
Lapis Lazuli | Level 10

Hi guys, 

suppose to have a data set1 with column names and another data set2 with other column names. The two data sets have the same number of columns. Is there a way to allow data set2 to take column names of data set1 (position-wise)? 

 

 

Thank you in advance

1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Amethyst | Level 16

If TYPEs match on positions and LENGHTs agr "long enough" in set1, then the SQL union can do the job:

data set1;
  A=1;
  B="xyz";
  C=42;
run;


data set2;
  X=11;
  Y="abc";
  Z=421;
  output;
  X=12;
  Y="abd";
  Z=422;
  output;
run;


proc sql;
create table WANT as
select * from set1(obs=0)
union all
select * from set2
;
quit;

proc print data=WANT;
run;

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



View solution in original post

3 REPLIES 3
yabwon
Amethyst | Level 16

If TYPEs match on positions and LENGHTs agr "long enough" in set1, then the SQL union can do the job:

data set1;
  A=1;
  B="xyz";
  C=42;
run;


data set2;
  X=11;
  Y="abc";
  Z=421;
  output;
  X=12;
  Y="abd";
  Z=422;
  output;
run;


proc sql;
create table WANT as
select * from set1(obs=0)
union all
select * from set2
;
quit;

proc print data=WANT;
run;

 

Bart

_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



NewUsrStat
Lapis Lazuli | Level 10
Thank you very much! It works perfectly
andreas_lds
Jade | Level 19

@NewUsrStat wrote:

Hi guys, 

suppose to have a data set1 with column names and another data set2 with other column names. The two data sets have the same number of columns. Is there a way to allow data set2 to take column names of data set1 (position-wise)? 

 

 

Thank you in advance


Can't you fix the creation of dataste2, so it uses the correct names instead of the wrong ones?