BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Mirisage
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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

3 REPLIES 3
Tom
Super User Tom
Super User

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

Or add a PUT statement or FILE statement.

Cynthia_sas
SAS Super FREQ

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
Mirisage
Obsidian | Level 7

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

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 3 replies
  • 15501 views
  • 10 likes
  • 3 in conversation