BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Kayla_Tan222
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@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;

 

View solution in original post

5 REPLIES 5
Patrick
Opal | Level 21

@Kayla_Tan222 

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. 

Astounding
PROC Star
Never ever run a two line DATA step with just a Run; statement. You are lucky the second DATA step didn't work. It would have destroyed your data set.

Just repeat the LIBNAME statement in your second program to make the data available.
Kayla_Tan222
Calcite | Level 5

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;

Patrick
Opal | Level 21

@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;

 

Astounding
PROC Star

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.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 5 replies
  • 823 views
  • 1 like
  • 3 in conversation