Hello, I wanted to know if there is a way to output data to a SAS dataset in the PROC PRINT step. I want to create new dataset with the values I get in the PROC PRINT step and I could not think of any other alternative than this. Thanks, any help will be appreciated.
Show an example of what you're trying to do (including example data in the form of a datastep, and the specific proc print you're running.
Art, CEO, AnalystFinder.com
proc freq data=counties;
tables F0410180;
where diabetes=1;
run;
That is my proc print step. I want this output in the form of a SAS dataset. I am not sure what could be another way the same thing could be done. But as you can see the variable F0410180, I have another 8 variables similar to that which identifies the counties where diabetes=1. So I want to merge all those datasets after I have all the counties where diabetes=1.
That's a proc freq, not a proc print.
With proc freq you can get the same info output by using the out option. e.g.:
proc freq data=sashelp.class; tables age/ out=want; where sex='M'; run;
Conversely, if you want everything, you can use ODS.
Art, CEO, AnalystFinder.com
I am really sorry.
proc print data=sashelp.class; tables age/ out=want; where sex='M'; run;
I typed proc freq because I was trying some alternatives. I know how to get it using proc frequencies. I want to use proc print and get everything. Sometimes, it is really hard to explain what I am trying to do.
That proc print won't run as there is no TABLES option in proc print. Show a valid working example of what your trying to explain.
Art, CEO, AnalystFinder.con
Why proc print? Just use a datastep:
data want (keep=name); set sashelp.class; where sex eq 'M'; run;
Art, CEO, AnalystFinder.com
I don't see why you can't use a datastep. Your current code:
proc print data=counties; Var F0410180; where diabetes=1; run;
would print the same data as captured in the following datastep:
data want (keep=F0410180); set counties; where diabetes eq 1; run;
Art, CEO, AnalystFinder.com
@raajdesaii wrote:
I cannot use a data step. Just like gender which has two values, I am identifying the county there. I do not have the values done those counties. So it's not possible.
Explain in very detailed language why it is not possible.
The WHERE statement in Proc print works pretty much exactly the same as WHERE statement in a data step. So anything you can select for proc print can be selected in a data step with the exact same where statement.
If the hang up is that the data set might have more variables than you want then KEEP only the variable you want in the data step.
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 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.