BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
David_Billa
Rhodochrosite | Level 12

I want to create WANT dataset as mentioned below although if one of source dataset don't exist. I tried the code below but it is not working. In real life HAVE1 dataset exist for sure with some data but HAVE2 dataset will not exist all the time. HAVE1 and HAVE2 dataset will be in same structure.

 

So I want to dynamically write one code similar to the one mentioned below to create WANT dataset.

 

data have1;
	id=1;
	output;
run;

/*create dataset want even if have2 dataset don't exist*/
data want;
	set have1 have2;
run;

log:

 

26         data have1;
27         id=1;
28         output;
29         run;

NOTE: Compression was disabled for data set WORK.HAVE1 because compression overhead would increase the size of the data set.
NOTE: The data set WORK.HAVE1 has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds
      

30         
31         /*create dataset want even if have2 dataset don't exist*/
32         
33         data want;
34         set have1 have2;
ERROR: File WORK.HAVE2.DATA does not exist.
35         run;
1 ACCEPTED SOLUTION

Accepted Solutions
yabwon
Onyx | Level 15

Hi,

 

one more would be:

 

data have1;
	id=1;
	output;
run;

options NODSNFERR;

data want;
    set have1 have2;
run;

options DSNFERR;

 

All the best

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

7 REPLIES 7
David_Billa
Rhodochrosite | Level 12

So can't we accomplish this task without querying the metadata?

yabwon
Onyx | Level 15

Hi,

 

I think both, my and @Kurt_Bremser's, solutions are quite "without querying the metadata"-ish

 

All the best

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



yabwon
Onyx | Level 15

Hi,

 

If you have common prefix you could try:

 

data want;
  set have: ;
run;

all the best

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



yabwon
Onyx | Level 15

Or if the list is "twisted", then you can do it like that:

 

data _null_;
  call execute('data want; set ');

  length set $ 41; drop set;
  do until (set = " ");
    i+1;
  	set = scan("have1 have2 ABC something.else", i);
    if exist(set) then call execute(set);
  end;
  call execute('; run;');

  stop;
run;

 

All the best

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



yabwon
Onyx | Level 15

Hi,

 

one more would be:

 

data have1;
	id=1;
	output;
run;

options NODSNFERR;

data want;
    set have1 have2;
run;

options DSNFERR;

 

All the best

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



sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 7 replies
  • 1590 views
  • 13 likes
  • 4 in conversation