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

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
Onyx | Level 15

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
Onyx | Level 15

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
Pyrite | Level 9
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?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 555 views
  • 1 like
  • 3 in conversation