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

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
Meteorite | Level 14

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
Meteorite | Level 14

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
Quartz | Level 8
Thank you very much! It works perfectly
andreas_lds
PROC Star

@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?

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.

Find more tutorials on the SAS Users YouTube channel.

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