BookmarkSubscribeRSS Feed
klc326
Calcite | Level 5

Hi! I have two questions.

 

Question 1: I have a data set (that I imported as a csv from Excel) with prevalence data of 50 diseases. I only want to analyze 30 of these diseases, so I am trying to exclude/delete the observations with other 20. The variable is Disease and I have tried the following example:

 

data SelectedDiseases;

set AllDiseases;

if Disease = 'Zika Virus Infection' OR Disease = 'Malaria' OR Disease = "Flavivirus Infection of Unknown Species' THEN DELETE;

run;

 

I am wondering if the spaces are the problem?

 

Question 2: Once I figure out how to get my SelectedDiseases data subset, how do I store this in a library that is not the "work" library so that I do not have to delete the other diseases everyone I open SAS?

 

Thank you so much!

2 REPLIES 2
ballardw
Super User

@klc326 wrote:

Hi! I have two questions.

 

Question 1: I have a data set (that I imported as a csv from Excel) with prevalence data of 50 diseases. I only want to analyze 30 of these diseases, so I am trying to exclude/delete the observations with other 20. The variable is Disease and I have tried the following example:

 

data SelectedDiseases;

set AllDiseases;

if Disease = 'Zika Virus Infection' OR Disease = 'Malaria' OR Disease = "Flavivirus Infection of Unknown Species' THEN DELETE;

run;

 

I am wondering if the spaces are the problem?

 

Question 2: Once I figure out how to get my SelectedDiseases data subset, how do I store this in a library that is not the "work" library so that I do not have to delete the other diseases everyone I open SAS?

 

Thank you so much!


First is that you can shorten code by using the IN operator. You shown line of If could be replaced with

if Disease in ( 'Zika Virus Infection'  'Malaria'  "Flavivirus Infection of Unknown Species") THEN DELETE;

If you look closely at your posted code the quotes around the Flavivirus name do not match. If that is actually your code submitted then you have mismatched quotes and I would expect 1) not output, 2) possible message about "current quoted value" is long and may have mismatched quotes in the LOG.

 

The single most common issue with comparisons of text is spelling. Either you code has different capitalization or misses matching the spelling with extra or missing spaces. SAS when using equals or the In operator, expects exact matches for the spelling used. If instead of 'Zika Virus Infection' your data set actually has 'ZIka Virus Infection', seethe first i is capital letter, then there is no match. If your data values are not spelled consistently then sometimes using one of Upcase or Lowcase on the variables and make your comparison text in the code match with all upper or lower case letters.

 

Spaces at the beginning of value will not match. If the actual value is '   Zika Virus Infection' then your code wouldn't match the value. If this might be the case then you can use the STRIP or LEFT functions on the variable to remove the spaces at the start.

 

SAS will not care about spaces at the end.

 

You need to be aware that many of procedures such as Proc Print or Freq will left justify output text and in effect hide the fact that leading spaces exist.

 

Libraries are disk storage locations. You pick a name you like and assign path to the desired location.

 

Libname Mylib "c:\users\somename\folder"; assuming the path is legit will create the library in that folder.

REAL STRONG HINT: Start the path with either the root letter of the drive (Windoze) or disk mount point to have a complete path. Otherwise the path may be interpreted as relative to where SAS executes. In server installations such as Enterprise Guide, SAS Studio, or SAS On Demand the program may not see your local drive and you have to use a location the system allows. Whatever, start with the highest level of the drive you can use.

 

You would then use syntax like

Data Mylib.selecteddiseases;

either in your data step or copy the data set (Proc Copy, Proc Datasets are a couple by code) to the library.

 

Make sure you save your Libname statement as you need to make sure the library is available the next time you use SAS and the easiest is to make sure to run the Libname code at the beginning of the session.

 

 

japelin
Rhodochrosite | Level 12

A1.

There is a double quote in front of Flavivirus, so you can just change it to a single quote.

You can also use the in operator to express it like this.

 

data a;
  set sashelp.class;
  if Disease not in ('Zika Virus Infection', 'Malaria', 'Flavivirus Infection of Unknown Species');
run;

A2.

You can create it in the permanent library.

For example, in a Windows environment, you can use the following method.

 

libname temp 'C:\Temp';
data temp.SelectedDiseases;
  ...
run;

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 377 views
  • 0 likes
  • 3 in conversation