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?
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;
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?
PS Since your data step overwrote the dataset, you have to re-download it.
A dataset named in the DATA statement will be written to. If it exists, it will be overwritten, if not, created.
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 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.
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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.