BookmarkSubscribeRSS Feed
SSegBeaverBoy
Calcite | Level 5

Starting with PC-SAS and have been giving a SAS dataset  ccc.sas7bdat.

 

On that dataset is a variable that I have modified, I have made the new variable and dropped the previous variable.

 

How do I then get the new SAS dataset written back to the LIBNAME:

 

My current code:

 

libname wombat 'd:\rawdata';

data wombat.sra1 (drop = ssan); set one;

proc contents data=wombat.sra1;
run;

data _null_; set wombat.sra1; file 'd:\rawdata\ddd.sas7bdat'; 
run;

3 REPLIES 3
Cynthia_sas
SAS Super FREQ
Hi:
It is not clear from your example what you are trying to do. In your first DATA step program you are creating the SAS dataset SRA1 in the "WOMBAT" library location of d:\rawdata. WOMBAT.SRA1 is being created FROM the SAS dataset WORK.ONE.

Since you do not show how WORK.ONE is created, there must be a step missing in your current code. Where does WORK.ONE come from?

Next, it appears that WOMBAT.SRA1 will have all the same variable as WORK.ONE except that you will NOT have the variable SSAN in WOMBAT.SRA1 and you WILL have the variable SSAN in WORK.ONE.

You then run a PROC CONTENTS to see the information in the SAS dataset WOMBAT.SRA1.

It is your 3rd step that I find confusing. DATA _NULL_ generally tells SAS that you need to use the DATA step programming language, but you do NOT want to create a SAS dataset with the program. Your input to this program is the dataset, WOMBAT.SRA1 that you just created.

Here's the confusing part -- the use of a SAS dataset name in your FILE statement is completely confusing. In your original post, you refer to getting a file called ccc.sas7bdat and yet, nowhere in your program steps do you refer to ccc.sas7bdat. So that is one discrepancy between your statement of the problem and the code you've shown.

However, with a FILE statement in a DATA _NULL_ program, typically, you are either writing to FILE PRINT or FILE PRINT ODS or you are creating an ASCII text file usually with PUT statements to write your report or with PUT statements to create your ASCII text file.

A SAS dataset (such as you reference by the full name in your FILE statement) is a proprietary type of file. I would expect that you are seeing this note in your LOG:
NOTE: 0 records were written to the file 'd:\rawdata\ddd.sas7bdat'.

So even though it appears that the program works (because you will not see any ERROR messages), the fact that 0 records are created should be a warning that something is not happening the way you want. If you want to CREATE a dataset named ddd.sas7bdat in the d:\rawdata file location, then you need to do something like this:
data wombat.ddd;
set wombat.sra1;
run;

proc contents data=wombat.ddd;
run;

Then, when you look at the PROC CONTENTS output, you should see that the location of ddd.sas7bdat is in the d:\rawdata folder (assuming that is where you want it).

cynthia
SSegBeaverBoy
Calcite | Level 5

Thank you -- as a mainframe programmer of over 25 years, it has been too long understanding libraries and how to properly write out a file -- your code helped me realize that I needed to just use the libname and membernames of the dataset I was creating to get the job done.  I got it to work so I thank you !  Scott S

Reeza
Super User

Your code should be something like below. Please read the comments.

 

*Create library to get/put data;
libname wombat 'd:\rawdata';

*bring dataset into work library from wombat library;
data one (drop = ssan);  /*new dataset to be created*/
set wombat.sra1; /*Dataset being read from*/

new_var=ssan*2; /*create new var*/
run;

*examine contents of dataset one;
proc contents data=one;
run;

*write back to library;
data wombat.sra2; /*new dataset, back in wombat library*/
set one; /*dataset being read from*/
run;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 1709 views
  • 0 likes
  • 3 in conversation