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,
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.