• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Programming Expert

Solving All of Your Programming Headaches

  • HTML
  • JavaScript
  • jQuery
  • PHP
  • Python
  • SAS
  • Ruby
  • About
You are here: Home / SAS / SAS data _null_ – Create a SAS Dataset with No Records and Variables

SAS data _null_ – Create a SAS Dataset with No Records and Variables

April 28, 2022 Leave a Comment

In SAS, the _null_ keyword in a SAS Data Step allows us to create a SAS dataset with no records and variables. With _null_, surprisingly, we are able to many things in our SAS code.

In this post, you will learn the many benefits of using _null_ in your SAS code.

Using the SAS _null_ Keyword in Your SAS Code

The SAS keyword _null_ creates a SAS dataset with no observations and no variables.

You can use _null_ in a data step for both the input and output dataset.

If it is specified as the input dataset, then you will create a dataset with no observations and no variables as shown below.

data out;
    set _null_;
run;

Using _null_ in this case can be useful if you want to initialize an empty dataset and you will add records to that dataset in a SAS Macro loop, for example.

data out;
    set _null_;
run;

%macro example_loop;
    %do i = 0 %to 10;

        /* some calculations */

        data out other_dataset;
             set out;
        run;
    %end;
%mend;

Otherwise, if you are using _null_ as the output dataset, then nothing will be created after the data step.

Even though this may seem useless, there are actually many ways you can use data _null_ to perform different tasks in SAS.

The Many Uses of data _null_ in SAS

There are a number of ways you can use data _null_ in a SAS data step.

One very common way you can use data _null_ is to create macro variables.

You can use the symput() and symputx() subroutines to create SAS macro variables from values in a SAS data set.

For example, if you want to get a value from a specific variable and create a macro variable from that value, you can do so as shown below.

data _null_;
    set summary_dataset;
    if name = "Sally" then call symputx("SallyVar", variable);
run;

You can also use data _null_ to put different values to the log, such as the value of a variable after a calculation or information about the dataset.

For example, if you want to do a specific calculation and put that value to the log, then you can use data _null_

data _null_;
    x = 5 * 10;
    put x;
run;

The majority of cases you will use data _null_ for fall into these two categories – creating macro variables or putting information to the log.

Hopefully this article has been useful for you to learn how to use data _null_ in your SAS code.

Other Articles You'll Also Like:

  • 1.  SAS Greater Than or Equal to with GE or >=
  • 2.  Multiple Condition If Statements in SAS Macro Language
  • 3.  Identifying Duplicates in SAS with PROC SORT dupout Option
  • 4.  nodup vs nodupkey PROC SORT Options in SAS
  • 5.  SAS weekday function – Get Day of Week from Date Variable
  • 6.  SAS Lowercase – Make String Lowercase with SAS lowcase function
  • 7.  Using SAS to Sum by Group with PROC MEANS
  • 8.  Date Format ddmmmyyyy in SAS
  • 9.  SAS Month Year Format monyyw.
  • 10.  Round Number to 2 Decimal Places in SAS

About The Programming Expert

The Programming Expert is a compilation of a programmer’s findings in the world of software development, website creation, and automation of processes.

Programming allows us to create amazing applications which make our work more efficient, repeatable and accurate.

At the end of the day, we want to be able to just push a button and let the code do it’s magic.

You can read more about us on our about page.

Reader Interactions

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

About The Programming Expert

the programming expert main image

Welcome to The Programming Expert. We are a group of US-based programming professionals who have helped companies build, maintain, and improve everything from simple websites to large-scale projects.

We built The Programming Expert to help you solve your programming problems with useful coding methods and functions in various programming languages.

Search

Learn Coding from Experts on Udemy

Looking to boost your skills and learn how to become a programming expert?

Check out the links below to view Udemy courses for learning to program in the following languages:

Copyright © 2023 · The Programming Expert · About · Privacy Policy