- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can reference a SAS dataset in two ways:
- by supplying the complete physical path as a string (in quotes)
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
libname cert "C:\workshop\cert";
data work.data_out;
set cert.data_in;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content