Help using Base SAS procedures

A layman question on data _null_ ?

Accepted Solution Solved
Reply
Super Contributor
Posts: 338
Accepted Solution

A layman question on data _null_ ?

Hi SAS Forum,

I ran the below code.

data null;

today = today ();

format today date9.;

run;

proc print;

It created the below data set which is understandable.

1

03JUL2013

However, I ran below data _null_ code and it produced nothing, not anything in the log too. I know that data _null_ doesn’t produce a separate data set but it should show the values that were generated in the SAS log, isn’t it?

data _null_;

today = today ();

format today date9.;

run;

Q: Could anyone elaborate a bit what is really happening inside data _null_?

Thanks

Mirisage


Accepted Solutions
Solution
‎07-03-2013 05:25 PM
Super User
Super User
Posts: 6,497

Re: A layman question on data _null_ ?

Turn on the STIMER option.  Then you will get something in the log.

Or add a PUT statement or FILE statement.

View solution in original post


All Replies
Solution
‎07-03-2013 05:25 PM
Super User
Super User
Posts: 6,497

Re: A layman question on data _null_ ?

Turn on the STIMER option.  Then you will get something in the log.

Or add a PUT statement or FILE statement.

SAS Super FREQ
Posts: 8,740

Re: A layman question on data _null_ ?

Hi:

  In addition to Tom's suggestions, I would suggest that you read about DATA step processing. There -is- a difference between

data null; (no underscored in file name on DATA statement)

and

data _null_; (with underscores in the name on the DATA statement)

  You can see the difference in the attached screenshot of the SAS log. DATA NULL actually created the dataset WORK.NULL; while DATA _NULL_ told SAS that you wanted to use the programming language, but you did NOT want to create an output dataset. Note that for the second program with DATA _NULL_, there was no dataset created.

  In my opinion, it is not a good idea to just invoke PROC PRINT;, as you show in your posting. The reason is that the DATA= option would have made it abundantly clear that

data null;

... more code...

run;

proc print data=null;

run;

is the same as

data wombat;

...more code...

run;

proc print data=wombat;

run;

where the program creates work.null or work.wombat and the PROC PRINT will display either of the  created data sets.

But if you had done this:

data _null_;

...more code ...

run;

proc print data=_null_;

run;

You would have seen this note in the LOG:

NOTE: No variables in data set WORK._NULL_.

(See the second screen shot.) SAS assumes that in a PROC step, DATA=_NULL_ is supposed to look for WORK._NULL_ -- which you did NOT create. (You actually CANNOT create WORK._NULL_ in a DATA step program, so it is really important for you to understand what your program actually created.

As it says in the doc.Step-by-Step Programming with Base SAS(R) Software

"When you use the DATA _NULL_ statement, SAS processes the DATA step without writing observations to a data set." And, if you look at the DATA statement documentation,

SAS(R) 9.3 Statements: Reference you will see that there are 6 forms of DATA statement and DATA _NULL_ is form 2.

So, I could have used DATA _NULL_ to write a .TXT or ASCII text file with out creating a SAS dataset first. See the third screen shot.

  A DATA step program, by itself, does not operate like PROC PRINT. Normally when you use a DATA step program, you are creating a SAS dataset and you name the dataset on the DATA statement. All you see in a log is the creation messages or any output from your PUT or PUTLOG statements. So, then if you have a PROC PRINT, your PROC PRINT step will show output. But, when you use DATA _NULL_ (underscore-NULL-underscore), you do NOT create a SAS dataset. You use the Programming language for whatever reason. There are ONLY log messages. As you can see, the log messages are different depending on what you do in the program.

cynthia


examp_data_null_.pngwork_null_vs_data_null_.png_null_is_special_ref.png
Super Contributor
Posts: 338

Re: A layman question on data _null_ ?

Hi Cynthia,

Thank you very much for this enormous amount of knowledge and taking time to attach screenshots etc. helping me to understand what is happening.

Thanks again!

Hi Tom,

Thank you for this SAS trick.

Regards

Mirisage

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 4695 views
  • 5 likes
  • 3 in conversation