Hey everyone,
I am having trouble creating a permanent table for an activity in the Programming Course. More specifically:
"Write a DATA step to read the pg1.np_species table and create a new table named fox.
Note: If you are using SAS Studio, try creating fox as a permanent table in the EPG194/output folder"
* if you are creating a permanent table, you must submit a LIBNAME statement and then reference out.fox; * libname out "path-to-EPG194/output";
I am able to perform the steps and processes after this but for some reason I can't create a permanent table for this solution. It isn't required, but I want to know my mistake to better understand SAS. Below is my code.
libname out.fox;
libname out "/folders/myfolders/EPG194/output";
data fox;
set pg1.np_species;
where Category='Mammal' and upcase(Common_Names) like '%FOX%';
drop Category Record_Status Occurrence Nativeness;
run;
Thanks for the assistance.
*This does nothing;
libname out.fox;
*This creates a permanent library - output folder must exist already;
libname out "/folders/myfolders/EPG194/output";
*you have not specified the library so your data set is saved to WORK;
data fox;
set pg1.np_species;
where Category='Mammal' and upcase(Common_Names) like '%FOX%';
drop Category Record_Status Occurrence Nativeness;
run;
The correct code is as follows:
libname out "/folders/myfolders/EPG194/output";
data out.fox;
set pg1.np_species;
where Category='Mammal' and upcase(Common_Names) like '%FOX%';
drop Category Record_Status Occurrence Nativeness;
run;
The LIBNAME statement is only meant to associate a symbolic name (OUT in your example) to a location (or a set of location, but we don't need to go into that here).
References to data sets (or "table" in you example) are not made in a libname statement, but are made in DATA statements, SET, MERGE or a few other statements). I.e. that's where two-level names (libname.tablename) can occur.
So what did you sas log say
regards,
Mark
Sorry for the delay, I just started working and that took up the last few days. I figured out the issue. I wasn't referencing out correctly, and the path to the output folder somehow changed, making my reference incorrect. It is fixed now. Thank you for the help and explanation.
*This does nothing;
libname out.fox;
*This creates a permanent library - output folder must exist already;
libname out "/folders/myfolders/EPG194/output";
*you have not specified the library so your data set is saved to WORK;
data fox;
set pg1.np_species;
where Category='Mammal' and upcase(Common_Names) like '%FOX%';
drop Category Record_Status Occurrence Nativeness;
run;
The correct code is as follows:
libname out "/folders/myfolders/EPG194/output";
data out.fox;
set pg1.np_species;
where Category='Mammal' and upcase(Common_Names) like '%FOX%';
drop Category Record_Status Occurrence Nativeness;
run;
Thanks for the help and explanation. I initially had the path to the output folder wrong. When it didn't reference out I got confused and started making more mistakes.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.