Help using Base SAS procedures

Output Statement & Out= procedure option.

Accepted Solution Solved
Reply
Contributor
Posts: 22
Accepted Solution

Output Statement & Out= procedure option.

Hi Everyone,

 

A. Can anyone tell me when we use:

1. Output statement.

2. Out= (procedure option) and,

3. Output Out=

 

B. Can we use all 3 statements/options in SAS DATA sets?

    By SAS DATA SET I mean for example:

    data male female;

    set demographic;

    if gender = 'F' then output female;

    if gender = 'M' then output male;

    run;

 

C. Can we use all 3 statements/options in SAS Procedures?

 

D. 'Output out = ' is a procedure option or a statement?

 

Please give me some examples also, if possible.

 

Thanks,

Ramanuj


Accepted Solutions
Solution
‎04-09-2016 10:06 AM
Trusted Advisor
Posts: 1,115

Re: Output Statement & Out= procedure option.

[ Edited ]

Hi @Ramanuj_Khatri,

 

You're probably familiar with other programming languages which have essentially one set of statements, functions etc. SAS (more precisely: the SAS programming language) is different from those languages. There is only little overlap between the DATA step language and language elements used in SAS procedures. Moreover, each procedure has its own syntax. There are similarities between certain procedures, but the list of statements with the same function in multiple (Base SAS) procedures is short.

 

Therefore, I think, the basic picture to start with is

  • DATA step
  • procedures:
    - PROC CONTENTS
    - PROC PRINT
    - PROC SORT
    - PROC FREQ
    etc.
  • global statements (LIBNAME, TITLE, OPTIONS, etc.) and comments

 

Natural questions would be "How can I ...?"

  • derive a new quantity from existing values
  • compute group means of a series of measurements
  • display data of selected subjects
    ...

The answers to such questions will lead you to syntax elements. When you read about the syntax, e.g., of a particular procedure statement, it is a good idea to quickly look through other syntax elements of the same procedure that may be useful later.

 

As to your questions:


A1. There is an OUTPUT statement in the DATA step (which writes the current observation to a dataset) and there are OUTPUT statements in many procedures (see this list), but they are completely separate.

 

A2, A3. As described above, each procedure has its own syntax. Some procedures have statements with an OUT= option to create a dataset containing procedure results.

 

B. SAS datasets contain data. What you describe is a DATA step containing a SET statement. Only the OUTPUT statement (of the DATA step) is valid here, no procedure syntax.

 

C. Not all procedures have an OUTPUT statement or statements with an OUT= option (e.g. PROC MEANS: yes, PROC PRINT: no).

 

D. OUT= in procedures (if existent) is always an option of a statement. For example, in PROC FREQ both the TABLES statement and the OUTPUT statement have an OUT= option.

View solution in original post


All Replies
Super Contributor
Posts: 408

Re: Output Statement & Out= procedure option.

Hi @Ramanuj_Khatri please avoid cross-posting. Answering the question is so much harder for a community. Please consider removing one version.

 

Regards, Jan.

Super User
Posts: 5,255

Re: Output Statement & Out= procedure option.

All your question can easily be found in SAS documentation and can be as easily verified by testing in a SAS session.
Data never sleeps
Contributor
Posts: 22

Output statement and Out= Procedure option

Hi Everyone,

 

A. Can anyone tell me when we use:

1. Output statement.

2. Out= (procedure option) and,

3. Output Out=

 

B. Can we use all 3 statements/options in SAS DATA sets?

    By SAS DATA SET I mean for example:

    data male female;

    set demographic;

    if gender = 'F' then output female;

    if gender = 'M' then output male;

    run;

 

C. Can we use all 3 statements/options in SAS Procedures?

 

D. 'Output out = ' is a procedure option or a statement?

 

Please give me some examples also, if possible.

 

Thanks,

Ramanuj

Super Contributor
Posts: 408

Re: Output statement and Out= Procedure option

Hi @Ramanuj_Khatri please avoid cross-posting. Answering the question is so much harder for a community. Please consider removing one version.

 

Regards, Jan.

Solution
‎04-09-2016 10:06 AM
Trusted Advisor
Posts: 1,115

Re: Output Statement & Out= procedure option.

[ Edited ]

Hi @Ramanuj_Khatri,

 

You're probably familiar with other programming languages which have essentially one set of statements, functions etc. SAS (more precisely: the SAS programming language) is different from those languages. There is only little overlap between the DATA step language and language elements used in SAS procedures. Moreover, each procedure has its own syntax. There are similarities between certain procedures, but the list of statements with the same function in multiple (Base SAS) procedures is short.

 

Therefore, I think, the basic picture to start with is

  • DATA step
  • procedures:
    - PROC CONTENTS
    - PROC PRINT
    - PROC SORT
    - PROC FREQ
    etc.
  • global statements (LIBNAME, TITLE, OPTIONS, etc.) and comments

 

Natural questions would be "How can I ...?"

  • derive a new quantity from existing values
  • compute group means of a series of measurements
  • display data of selected subjects
    ...

The answers to such questions will lead you to syntax elements. When you read about the syntax, e.g., of a particular procedure statement, it is a good idea to quickly look through other syntax elements of the same procedure that may be useful later.

 

As to your questions:


A1. There is an OUTPUT statement in the DATA step (which writes the current observation to a dataset) and there are OUTPUT statements in many procedures (see this list), but they are completely separate.

 

A2, A3. As described above, each procedure has its own syntax. Some procedures have statements with an OUT= option to create a dataset containing procedure results.

 

B. SAS datasets contain data. What you describe is a DATA step containing a SET statement. Only the OUTPUT statement (of the DATA step) is valid here, no procedure syntax.

 

C. Not all procedures have an OUTPUT statement or statements with an OUT= option (e.g. PROC MEANS: yes, PROC PRINT: no).

 

D. OUT= in procedures (if existent) is always an option of a statement. For example, in PROC FREQ both the TABLES statement and the OUTPUT statement have an OUT= option.

Contributor
Posts: 22

Re: Output Statement & Out= procedure option.

Hi, 

 

A. Is it true that output statement (without an out= option) is valid only in DATA Steps. If no, then,
please describe me (don't give only names) atleast two examples of sas procedures where no 'out=' option is required after output statement.
However, I know that: If the OUT= (or DATA=) option is omitted, the procedure uses the DATAn convention to name the output data set. So, please don't use proc means, proc summary etc.

 

And please, ignore this:

 

B. Can we use all 3 statements/options in SAS DATA sets?
By SAS DATA SET I mean for example:
data male female;
set demographic;
if gender = 'F' then output female;
if gender = 'M' then output male;
run;

 

And, consider this as: Can we use out= or output out= in DATA steps? If yes, then please give me 1 or 2 examples.


Thanks,
Ramanuj

Trusted Advisor
Posts: 1,115

Re: Output Statement & Out= procedure option.

[ Edited ]

I can only reiterate that the OUTPUT statement of the DATA step and the OUTPUT statements found in some SAS procedures have little in common except their name. It would be a misconception to think of "the OUTPUT statement" as a language element shared by the DATA step and some SAS procedures. Maybe it would avoid confusion if the OUTPUT statement of the DATA step was rather called "WRITE" or something.

 

You could go through the long list of SAS procedures which have an OUTPUT statement (linked also in my previous post) and try to find one without an OUT= option, but for what purpose? From the top of my head (but I haven't used every procedure in that list) I guess that each of these OUTPUT statements has an OUT= option. Obviously, the "output" must be written somewhere and an output dataset makes much sense, hence there is a need to specify the dataset name. For consistency, the pertinent option of the OUTPUT statements was named OUT= in many if not all SAS procedures which have an OUTPUT statement.

 

So, yes, if you encounter a line of SAS code that reads output; or output abc; you're most likely reading a DATA step. (You mentioned the rare exception of the default-named DATAn datasets created by PROC steps yourself.)

 

The OUTPUT statement of the DATA step does not have any options (SAS 9.4 documentation), in particular no OUT= option.

Contributor
Posts: 22

Re: Output Statement & Out= procedure option.

Thanks for your last answer.
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 596 views
  • 2 likes
  • 4 in conversation