Can anyone tell me what would be the code for creating multiple dataset from one dataset in one data step?
Example: I have the following info dataset
Name City Country
John New York USA
Albert Toronto Canada
Alice Sydney Australia
I want to create 3 dataset called USA, Canada and Australia from info dataset above. I tried the following way, but it's not working:
data usa canada australia;
set info;
if country='usa' then output usa;
if country='Canada' then output Canada;
if country='Australia' then output Australia;
run;
can anyone help please. Thanks.
Your code should work, other than the fact that you will get zero obs in the USA data set since the value of country in your example is USA not the usa that your IF statement is testing.
Character comparison is case sensitive. So usa is not equal to USA.
If you'll have mixed case in between observations you can use upcase function.
Hi,
You can try below code. it should work.
data usa canada australia;
set info;
if upcase(country)='USA' then output usa;
if upcase(country)='CANADA' then output Canada;
if upcase(country)='AUSTRALIA' then output Australia;
run;
When you use upcase function. String should be in upper case as above. whatever case in data, it should be populated in the output.
Let me know if you need any help.
Thanks,
Yaswanth J.
data usa canada australia ;
set info;
select (upcase(country));
when ('USA') output usa;
when ('CANADA') output canada;
when ('AUSTRALIA') output Australia;
otherwise;
end;
run;
Hi Sir,
Please use following if statement.
If country = "USA" then output usa;
Instead of
if country = "usa then output usa;
Then you will get your desirable output.
Thanks,
Gnaneshwar,
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.