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

I got this question on practise exams for certification, i set dataset (&library) without  double quotation it didnt work for me, when i used  "&library" i could create the dataset.

But answer i got in SAS site is - &library without double quotes

 

Complete the code below to reference a data set named data_in that is contained in the library cert. You must use the macro variable defined in the program in place of the library name.

 

 

%let library = cert.data_in; libname cert "C:\workshop\cert";

data work.data_out; set Answer; run;

 

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

@vidyapedii wrote:

Hi, Thankyou for the response,

 

%let library= /home/vidyapedii0/CERT/INPUT/input04;

 

I created macro named "library" to reference the "input04" dataset in Cert library, i used "&library" in set statement to create another dataset.

which is the correct way to use macro var library with quotes ( ex-"&library")  or without quotes  (ex -  &library)

i got this question in practise exam, answer they have mentioned is without quotes(&library), but i couldn't create the dataset when i used macro variable without quotes (&library)

 
%let library=/home/vidyapedii0/CERT/INPUT/input04;
data let;
 set "&library";
run;

You created the macro variable LIBRARY to point to a FILE that has the dataset INPUT04.  You made no use of a LIBRARY (or more exactly a LIBREF) named CERT.  When you reference a dataset by the filename you need to enclose the values in quote (whether or not you use any macro variable).  

These example SET statements all reference the same file (and so the same dataset).

set '/home/vidyapedii0/CERT/INPUT/input04';
set "/home/vidyapedii0/CERT/INPUT/input04";
set "/home/vidyapedii0/CERT/INPUT/input04.sas7bdat";

%let filename = '/home/vidyapedii0/CERT/INPUT/input04';
set &filename;

%let filename = /home/vidyapedii0/CERT/INPUT/input04;
set "&filename";

If you use a LIBNAME statement to define a libref that defines a specific library then to reference the members of that library you use a two level name without any quotes. Whether or not you use a macro varaible.

libname cert '/home/vidyapedii0/CERT/INPUT/';
set cert.input04;

%let dataset_name = cert.input04;
set &dataset_name;

%let member_name = input04 ;
set cert.&member_name;

 

 

View solution in original post

9 REPLIES 9
vellad
Obsidian | Level 7

 i set dataset (&library) without  double quotation it didnt work for me

Can you show us your log? It should work without the quotes:

data work.data_out; 
   set &library; 
run;
vidyapedii
Fluorite | Level 6

i am getting error like this

73 %let library=/home/vidyapedii0/CERT/INPUT/input04;
74 data let;
75 set &library;
NOTE: Line generated by the macro variable "LIBRARY".
75 /home/vidyapedii0/CERT/INPUT/input04
_
22
76
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS,
NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.

ERROR 76-322: Syntax error, statement will be ignored.
vellad
Obsidian | Level 7

Why do you need to change the macro variable definition from what's been given? It is given as cert.data_in but you are changing to the physical path, which won't work with the set statement without the quotes! Try it the way I suggested in my previous post.

vidyapedii
Fluorite | Level 6
i can read the data with "&library" in set statement
 
73 %let library=/home/vidyapedii0/CERT/INPUT/input04;
74 data let;
75 set "&library";
NOTE: Data file CERT.INPUT04.DATA is in a format that is native to another host, or the file encoding does not match the session
encoding. Cross Environment Data Access will be used, which might require additional CPU resources and might reduce
performance.
76 run;
 
NOTE: There were 20 observations read from the data set /home/vidyapedii0/CERT/INPUT/input04.
NOTE: The data set WORK.LET has 20 observations and 15 variables.
Kurt_Bremser
Super User

You can reference a SAS dataset in two ways:

  1. by supplying the complete physical path as a string (in quotes)
  2. by using a library and a dataset name, separated by a period; here no quotes are used

The second method is preferred; first assign the libname, then use the libname.dataset in the SET statement:

libname input "/home/vidyapedii0/CERT/INPUT";

data let;
set input.input04;

You can see that this SET statement is easier to read than one with the full path in quotes.

Tom
Super User Tom
Super User

It is hard to tell from your question but I think the purpose of the question was to get you to say want text should replace the string Answer in this code:

libname cert "C:\workshop\cert";
data work.data_out;
  set Answer; 
run;

There is no need to create or reference a macro variable LIBRARY.  Instead you want to reference the libref CERT that the code created in the LIBNAME statement.

Spoiler
libname cert "C:\workshop\cert";
data work.data_out;
  set cert.data_in; 
run;

 

vidyapedii
Fluorite | Level 6

Hi, Thankyou for the response,

 

%let library= /home/vidyapedii0/CERT/INPUT/input04;

 

I created macro named "library" to reference the "input04" dataset in Cert library, i used "&library" in set statement to create another dataset.

which is the correct way to use macro var library with quotes ( ex-"&library")  or without quotes  (ex -  &library)

i got this question in practise exam, answer they have mentioned is without quotes(&library), but i couldn't create the dataset when i used macro variable without quotes (&library)

 
%let library=/home/vidyapedii0/CERT/INPUT/input04;
data let;
 set "&library";
run;
Tom
Super User Tom
Super User

@vidyapedii wrote:

Hi, Thankyou for the response,

 

%let library= /home/vidyapedii0/CERT/INPUT/input04;

 

I created macro named "library" to reference the "input04" dataset in Cert library, i used "&library" in set statement to create another dataset.

which is the correct way to use macro var library with quotes ( ex-"&library")  or without quotes  (ex -  &library)

i got this question in practise exam, answer they have mentioned is without quotes(&library), but i couldn't create the dataset when i used macro variable without quotes (&library)

 
%let library=/home/vidyapedii0/CERT/INPUT/input04;
data let;
 set "&library";
run;

You created the macro variable LIBRARY to point to a FILE that has the dataset INPUT04.  You made no use of a LIBRARY (or more exactly a LIBREF) named CERT.  When you reference a dataset by the filename you need to enclose the values in quote (whether or not you use any macro variable).  

These example SET statements all reference the same file (and so the same dataset).

set '/home/vidyapedii0/CERT/INPUT/input04';
set "/home/vidyapedii0/CERT/INPUT/input04";
set "/home/vidyapedii0/CERT/INPUT/input04.sas7bdat";

%let filename = '/home/vidyapedii0/CERT/INPUT/input04';
set &filename;

%let filename = /home/vidyapedii0/CERT/INPUT/input04;
set "&filename";

If you use a LIBNAME statement to define a libref that defines a specific library then to reference the members of that library you use a two level name without any quotes. Whether or not you use a macro varaible.

libname cert '/home/vidyapedii0/CERT/INPUT/';
set cert.input04;

%let dataset_name = cert.input04;
set &dataset_name;

%let member_name = input04 ;
set cert.&member_name;

 

 

vidyapedii
Fluorite | Level 6
Thank you for your response, now i got correct output

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 3394 views
  • 2 likes
  • 4 in conversation