Hello,
I would like to build new data `all`, with 10 ds: ds_1 to ds_10. however ds_5 is an empty dataset. what should I do?
currently I have following codes but it wont give me the ds I want:
```
data all;
set ds_:;
run;
```
Is it a smart way to build all without picking out the empty ds_*?
Thanks.
An empty dataset, meaning 0 obs, should not be a problem. Below test code runs fine:
data ds_1 ds_2(where=(0)) ds_3 ;
do i=1 to 5 ;
output ;
end ;
run ;
data all ;
set ds_: ;
run ;
Can you share a small example of your problem?
@stataq wrote:
Hello,
I would like to build new data `all`, with 10 ds: ds_1 to ds_10. however ds_5 is an empty dataset. what should I do?
currently I have following codes but it wont give me the ds I want:
```
data all;
set ds_:;
run;
```
Is it a smart way to build all without picking out the empty ds_*?
Thanks.
Explain what happens when you try this. Do you get an error? If so, show us the log. Do you get the wrong result? If so, explain what is wrong.
When I try this, it works fine. No errors in the log. Expected output.
/* Create fake data */
data ds_1 ds_2;
set sashelp.class;
if name='Jane' then output ds_1;
else if name='Robert' then output ds_2;
run;
data ds_3;
delete;
run;
data all;
set ds_:;
run;
When I look further, I found 1 var in datasets has been defined as both character and numeric. Is it a quick way to fix this?
For example: var `test1` should be a character var, but when it is all empty, ds_* put it as numeric. How can I update `test1` in all ds_* to character?
@stataq wrote:
When I look further, I found 1 var in datasets has been defined as both character and numeric. Is it a quick way to fix this?
For example: var `test1` should be a character var, but when it is all empty, ds_* put it as numeric. How can I update `test1` in all ds_* to character?
You really have to fix the process that is creating your data sets, even your empty data sets
Show the code that makes that empty data set.
And may require going back multiple steps in your process.
The reason to fix the process is moderately simple. I could "fix" one data set for one variable pretty easily. Suppose the next time around you have 5 data sets with the same variable character and 5 with the variable numeric. Which should be which? Fixing 5 sets gets to be more work. And if you start having this issue with multiple variables the work increases exponentially. Fix the process one time and you don't have to deal with it again.
Of course this begs the whole "empty dataset" question which is a similar kettle of fish.
Agree with @ballardw , there's isn't a quick fix for a variable type mismatch. Best would be to go back and solve why empty datasets have variables with the wrong type.
If you don't want to do that, messier hack would be to add a step to check all of your ds_* datasets and delete any of them that have 0 obs, before you use SET ds_: ; to concatenate them.
Show us the LOG resulting from that code.
Then describe what is not present that you want. Or what is present that you don't want.
I'm afraid that "give me the ds I want" requires mindreading to know what you want which is notoriously unreliable over the internet.
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.
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.