Hi,
I have a sas data set that I have save previously in a sas program lets say SAS PROGRAM 1.
and now I want to open it in another program (not related to SAS PROGRAM 1).
The code below is the way I used to save the sas data set in SAS PROGRAM 1,
libname mylib "C:\Data\PL\FILE\";
DATA mylib.pl;
(body ......)
run;
I try to use the code below to open it in another new program but it is not work and keep saying that the libref is not assigned.
DATA mylib.pl;
run;
What can I do with this problem?
@Kayla_Tan222 wrote:
is this what you meant? But I tried is not work, the output data is blank in the new sas session.
libname PL201811 "\\KAIWKSGH415THW5\Data\POLA\FILE\";
DATA PL201811.pola_clm_agg_201811;
run;
That's because you create a new data set with no content right here in your code. This overwrites the same named data set from your other job.
DATA <something>; creates new tables. To read from an already existing table use the SET statement.
data new;
set PL201811.pola_clm_agg_201811;
run;
You need the libname in all of your independent programs because this instructs SAS where to look for the table and what engine to use.
The alternative ways are:
1. If you're using SAS EG then have the libname statement in your EG project as code that gets executed when starting an EG session
2. Have the libname statement in an autoexec
3. Define the libname as pre-assigned library in SAS metadata
Most likely only alternative 1) is available to you and would make sense.
....having said all of the above:
Once you define a libname it's available to you anywhere in the same SAS session and though you wouldn't need to have it in every single program. That's what alternative 1) basically does for you.
But without alternative 1) the safe way is to just have the libname statement in every single piece of independent code you write.
is this what you meant? But I tried is not work, the output data is blank in the new sas session.
libname PL201811 "\\KAIWKSGH415THW5\Data\POLA\FILE\";
DATA PL201811.pola_clm_agg_201811;
run;
@Kayla_Tan222 wrote:
is this what you meant? But I tried is not work, the output data is blank in the new sas session.
libname PL201811 "\\KAIWKSGH415THW5\Data\POLA\FILE\";
DATA PL201811.pola_clm_agg_201811;
run;
That's because you create a new data set with no content right here in your code. This overwrites the same named data set from your other job.
DATA <something>; creates new tables. To read from an already existing table use the SET statement.
data new;
set PL201811.pola_clm_agg_201811;
run;
You got the part right about copying the LIBNAME statement.
However you ignored the part about "Never ever". So you have now destroyed your data set and need to re-create it using your earlier program.
You absolutely must, must, must learn the meaning of basic statements in SAS. LIBNAME is only one of them. Taking your posts as a whole, you also need to know the meaning of a DATA statement, a SET statement, how to keep and drop variables, how to refer to values of character variables, how to use parentheses in an IF THEN statement, and you must read the SAS log and understand the notes that SAS is providing there. There's more, but those are the points that stand out from the recent posts you have made. You must take a course ... there are free online courses available. And don't even think of using macro language for the next six months until you know these basics inside and out.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: