Hello:
I have the follow codes, what is the n used for after "April" ? Why the test have double quotation marks? Thanks.
PROC CONTENTS DATA=work."April"n
OUT=AprilOut NOPRINT;
RUN;
That looks like a SAS name literal. From the following paper
"Name literals are most useful when accessing databases (and Excel spreadsheets) that may have non-standard column names. (for example, they might contain a space or an ampersand.)"
'Total Monthly Sales'n would be another example of a name literal, since it contains spaces.
Literals can use either single or double quotes. I'm not sure why they are using a name literal for "April" since it doesn't have any special characters, but it shouldn't hurt to use it either way.
@ybz12003 wrote:
Hello:
I have the follow codes, what is the n used for after "test" ? Why the test have double quotation marks? Thanks.
PROC CONTENTS DATA=work."April"n OUT=AprilOut NOPRINT; RUN;
There is no "test" in your code, and the name literal "April"n is not necessary, as April is a valid V7 SAS name.
You are right, I type the wrong word. I should have use "April" instead of "test".
That looks like a SAS name literal. From the following paper
"Name literals are most useful when accessing databases (and Excel spreadsheets) that may have non-standard column names. (for example, they might contain a space or an ampersand.)"
'Total Monthly Sales'n would be another example of a name literal, since it contains spaces.
Literals can use either single or double quotes. I'm not sure why they are using a name literal for "April" since it doesn't have any special characters, but it shouldn't hurt to use it either way.
Generally an n used that way indicates use of a name literal. If the SAS option VALIDVARNAME is set to ANY then the names of variables may contain characters that are not normally acceptable. The quotes enclose the text as one of the characters that might occur in these names is a space. The n immediately after indicates name literal as the d does for dates such as "01JAN2018"d. The quotes could be single or double.
The option VALIDMEMNAME set to EXTEND does similar for Member names: data sets, data views or item stores.
The intent is basically to allow working with the names of things in external databases that allow such extra characters.
Personally, I find it a chore to work with and rename things as soon as practical to standard SAS names.
So I come up a question. There are several datasets in my work folder, which including "April", "April_first", "April_middle", "April_end". When I use proc content statement, does it mean I am looking for all the dataset containing "April", or just the file "April"?
For PROC CONTENTS it is just the single dataset named.
But you can use the special token _ALL_ and it report on all of the datasets in the library.
proc contents data=mylib._all_ noprint out=contents; run;
You could then filter the output data based on the member name if you wanted the information for some of them.
data want ;
set contents;
where upcase(memname) like 'APRIL%';
run;
Thank you for all of the thoroughly explanation, step by step. It's very helpful for me to understand.
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 25. 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.