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

I'm a student and taking SAS course with intensive project work. While I was working on SAS proc correlation and proc regression, I tried to drop some variable using the following code and by SAS project variables not appear after I tried this code. How Can I keep them back?

data work.my_data;

    call streaminit(123);

 

    do i = 1 to 1000;

         my_var = rand("Normal", 0, 1);

         output;

    end;

 

    drop i;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Drop does just that, drops the variable(s) from the output (or if used as a data set option before the data is brought into the data vector).

 

Where do  you want the variable? If it is to be in the same data set then remove the drop statement.

If you want multiple data sets, one with and one without the "dropped" variable you can do so at creation:

 

data work.my_data (drop=i)
     work.datawithdrop
;
   call streaminit(123);

   do i = 1 to 1000;
      my_var = rand("Normal", 0, 1);
      output;
   end;
run;

The two data set names on the DATA statement means data may be written to both. In this case all the records will be written to both data sets. The first data set uses the option to drop the variable i when records are written to it.

View solution in original post

1 REPLY 1
ballardw
Super User

Drop does just that, drops the variable(s) from the output (or if used as a data set option before the data is brought into the data vector).

 

Where do  you want the variable? If it is to be in the same data set then remove the drop statement.

If you want multiple data sets, one with and one without the "dropped" variable you can do so at creation:

 

data work.my_data (drop=i)
     work.datawithdrop
;
   call streaminit(123);

   do i = 1 to 1000;
      my_var = rand("Normal", 0, 1);
      output;
   end;
run;

The two data set names on the DATA statement means data may be written to both. In this case all the records will be written to both data sets. The first data set uses the option to drop the variable i when records are written to it.

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 372 views
  • 0 likes
  • 2 in conversation