DATA Step, Macro, Functions and more

PROC PRINT

Reply
Occasional Contributor
Posts: 8

PROC PRINT

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. 

PROC Star
Posts: 8,117

Re: PROC PRINT

Posted in reply to raajdesaii

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

 

Occasional Contributor
Posts: 8

Re: PROC PRINT

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. 

PROC Star
Posts: 8,117

Re: PROC PRINT

Posted in reply to raajdesaii

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

 

Occasional Contributor
Posts: 8

Re: PROC PRINT

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.  

PROC Star
Posts: 8,117

Re: PROC PRINT

Posted in reply to raajdesaii

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

 

Occasional Contributor
Posts: 8

Re: PROC PRINT

Posted in reply to raajdesaii
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.
PROC Star
Posts: 8,117

Re: PROC PRINT

Posted in reply to raajdesaii

Why proc print? Just use a datastep:

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

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 8

Re: PROC PRINT

Posted in reply to raajdesaii
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.
PROC Star
Posts: 8,117

Re: PROC PRINT

Posted in reply to raajdesaii

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

 

Super User
Posts: 13,084

Re: PROC PRINT

Posted in reply to raajdesaii

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

 

Ask a Question
Discussion stats
  • 10 replies
  • 132 views
  • 0 likes
  • 3 in conversation