BookmarkSubscribeRSS Feed
Jianan_luna
Obsidian | Level 7

1. When I do the practice in programming 1:essentials, some statements use the NODUPRECS statement other than the NODUPKEY statement. What's the difference between those two?

2. Some questions ask for formatting commas with decimal places. But I don't know how to decide the proper width of length. Can I round it? An example like comma6., what does 6 stand for? 

3. I saw some questions use " ", some use '', is there any difference?

4. one question ask for "Write a DATA step to read the pg1.np_species table and create a new table named fox.
Note: If you are using SAS Studio, try creating fox as a permanent table in the EPG1V2/output folder." But there is no answer for libname statement. I am not sure whether it's correct.

libname out "path-to-EPG1V2/output.fox";
data fox;
    set pg1.np_species;
    where Category='Mammal' and upcase(Common_Names) like '%FOX%' 
        and upcase(Common_Names) not like '%SQUIRREL%';    
    drop Category Record_Status Occurrence Nativeness;
run;

Thanks so much!

 

 

 

3 REPLIES 3
Reeza
Super User

@Jianan_luna wrote:

1. When I do the practice in programming 1:essentials, some statements use the NODUPRECS statement other than the NODUPKEY statement. What's the difference between those two?

 


NODUPRECS is deprecated. It is still supported for backwards compatibility, but you should use NODUPKEY instead. The way NODUPRECS behaviour is not what most people expect it to do, so that's likely why it was removed and NODUPKEY is pretty clear.

 

https://communities.sas.com/t5/SAS-Programming/proc-sort-with-nonduprecs-does-not-work-with-data-ds-...

 


2. Some questions ask for formatting commas with decimal places. But I don't know how to decide the proper width of length. Can I round it? An example like comma6., what does 6 stand for? 


Formats take the format formatName<width>.<decimal> where the width and decimal portions are optional. The w tells you the entire length for the format including any special symbols such as a negative sign, decimal point, percent (counts as two spaces). The decimal portion specifies the number of decimals to show after the decimal point and needs to be factored in to the width as well. If you want to display 99,999.99 that has a width of 9, 7 for the digits, 1 for the comma and 1 for the decimal place.

 

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.5&docsetId=leforinforref&docsetTarge...

 


3. I saw some questions use " ", some use '', is there any difference?


The primary difference is how it resolves & and %. & and % are part of the SAS macro language and if you have double quotes it will treat them as macro components. Within single quotes they will be treated as character values. 

In general, for what you're learning now it shouldn't matter until you get to macros. 

 

More information can be found in this tutorial:

UCLA introductory tutorial on macro variables and macros
https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/

 


4. one question ask for "Write a DATA step to read the pg1.np_species table and create a new table named fox.
Note: If you are using SAS Studio, try creating fox as a permanent table in the EPG1V2/output folder." But there is no answer for libname statement. I am not sure whether it's correct.

libname out "path-to-EPG1V2/output.fox";
data fox;
    set pg1.np_species;
    where Category='Mammal' and upcase(Common_Names) like '%FOX%' 
        and upcase(Common_Names) not like '%SQUIRREL%';    
    drop Category Record_Status Occurrence Nativeness;
run;

Thanks so much!

 


No that is not correct. A library points to a location to save files for SAS data sets. You can use a libname to point at a file but that's not it's purpose here. 

So your libname is where your files are stored. Your data set fox, will be saved to the work library, not your library because you didn't reference in the DATA statement. 

https://libguides.library.kent.edu/SAS/libraries

Jianan_luna
Obsidian | Level 7

For example from question 2, 99,999.99, the format statement should be format name 9.2, is it right?

For Q4, I rewrite the code, LIBNAME fox ''EPG1V2/output";  is it right?

Thanks so much!

 

Reeza
Super User

For #1 no. 

For #2, not sure, try that one.

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 526 views
  • 1 like
  • 2 in conversation