BookmarkSubscribeRSS Feed
raajdesaii
Fluorite | Level 6

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. 

10 REPLIES 10
art297
Opal | Level 21

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

 

raajdesaii
Fluorite | Level 6

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. 

art297
Opal | Level 21

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

 

raajdesaii
Fluorite | Level 6

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.  

art297
Opal | Level 21

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

 

raajdesaii
Fluorite | Level 6
proc print data=counties;
Var F0410180;
where diabetes=1;
run;

 Okay, that is the code. So I already have a county identified for eg. Queens. F0410180, F0410280, F0410380, .... F04111380 are the variables which has the contiguous county next to the county I have already identified. And I want that county to follow the condition, where diabetes=1.

Now, I was thinking if I could create a SAS dataset using a Proc print which allows me to see all the counties which follows that condition. Please let me know if there is an alternative method by which I could identify those counties and merge them together along with all the other variables in the dataset.
art297
Opal | Level 21

Why proc print? Just use a datastep:

data want (keep=name);
  set sashelp.class;
  where sex eq 'M';
run;

Art, CEO, AnalystFinder.com

 

raajdesaii
Fluorite | Level 6
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.
art297
Opal | Level 21

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

 

ballardw
Super User

@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.

 

sas-innovate-2024.png

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.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1137 views
  • 0 likes
  • 3 in conversation