BookmarkSubscribeRSS Feed
ashb
Obsidian | Level 7

Hello everyone,

 

I am really new (and really bad) at SAS, and I am having trouble with having SAS read my data set correctly. Here is the code I wrote:

data 'C:\Users\bamfo\Downloads\bpx_j.sas7bdat';
run;

And this is the log I received:

1    data 'C:\Users\bamfo\Downloads\bpx_j.sas7bdat';
2    run;

NOTE: The data set C:\Users\bamfo\Downloads\bpx_j.sas7bdat has 1 observations and 0 variables.
NOTE: DATA statement used (Total process time):
      real time           0.13 seconds
      cpu time            0.06 seconds

I downloaded this dataset from my class website. I know from looking at my data without SAS that the amount of variables in the data set is much more lengthy than just 1 observation and 0 variables. Did I type something wrong?

14 REPLIES 14
Kurt_Bremser
Super User

The DATA statement initiates a data step, and the dataset(s) named in this statement will be created.

To use your dataset in a procedure (to print it, make a report, do analysis), you use it in the DATA= option of the respective PROCEDURE statement.

To read it into a data step, you either use the SET or MERGE statements.

The preferred way to use a dataset is to specify a LIBNAME and use the library to access it.

Example:

libname download "C:\Users\bamfo\Downloads";

data test; /* a single-level name will put this new dataset in library WORK */
set download.bpx_j;
run;
ashb
Obsidian | Level 7
Thanks for your detailed message. What do you mean by single level name?
Kurt_Bremser
Super User
data test; /* no library specified - single level */
set download.bpx_j; /* library specified - two level */

@ashb wrote:
Thanks for your detailed message. What do you mean by single level name?

 

ashb
Obsidian | Level 7
Got it, thanks!
ashb
Obsidian | Level 7
So basically using data instead of libname in the first line of code overwrites the dataset?
ashb
Obsidian | Level 7
The notes say that libname is used to create a permanent library to access data sets from. This is the preferred way, however in the Little SAS book, I read that the data step can be used to directly read a dataset into SAS without specifying or creating a library using libname. Or perhaps I'm misinterpreting what they mean?
ChrisNZ
Tourmaline | Level 20

1. The data keyword creates a data set, so you not reading anything here.

  You have overwritten your data set actually.

 

2. Surely you have learnt how to use SAS. What the keyword to start a statement when you want to read a data set?

 

3. I am unsure how you are taught, but the string  sas7bdat   is normally never seen in a program.

What does your course say?

 

ashb
Obsidian | Level 7
I know the step is libname, but I thought you could use data to directly read a dataset into SAS without specifying a library?
Kurt_Bremser
Super User

@ashb wrote:
I know the step is libname, but I thought you could use data to directly read a dataset into SAS without specifying a library?

Yes, you can, but no, you don't.

Using a library definition (LIBNAME) and a two-level name (library.dataset) is much easier than always writing out the complete filename. And if the location changes, you change ONE libname definition instead of a gazillion DATA/SET/MERGE/whatever statements or options.

ashb
Obsidian | Level 7
I see. That may be my problem then, because I would have trouble with coding with other assignments after using the data step rather than the libname step.
Kurt_Bremser
Super User

Once you have libraries for locations defined, you can always use them. Translating whole filenames to libname.dataset notation will be a breeze once you've done it a few times.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 14 replies
  • 2390 views
  • 4 likes
  • 3 in conversation