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

Hi all,

This is a beginner's question.

I am unsure about the correct statement to include in the following program to display only certain values of a few variables.

I need a final output where '' Country eq 'AU' and Job_Title contains 'Sales Rep'; ''

When I use the where  or if statement in my data step, it's not working. What statement should I use?

Should it be in the data step if perhaps in the proc print step?

All the examples I am trying to find are using the where statement with a set statement while my program uses an infile statement. 

This example contains a dataset csv file.

Please see below the program.

Thank you in advance for your help,

 

libname learn '/home/XXX/learn/';

Filename Emp '/home/XXX/learn/emp.csv'

Data learn.Emp

(keep = EmployeeID FirstName LastName Salary JobTitle HireDate); infile Emp dsd ; *if Job_Title contains 'Sales Rep' and Country eq 'AU'; *where Country eq 'AU' and JobTitle contains 'Sales Rep' informat Hire_Date date9.; input EmployeeID FirstName $ LastName $ Gender $ Salary JobTitle $ Country $ HireDate ; format Salary dollar8. HireDate mmddyy10.; run; Title 'Listing of Sales Representatives in Australia'; Proc print data = Emp; run;
1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

The condition should be evaluated AFTER the variables get a value. CONTAINS is only for WHERE and SQL.

 

libname learn '/home/XXX/learn/';

Filename Emp '/home/XXX/learn/emp.csv';
Data learn.Emp (keep = EmployeeID FirstName LastName Salary JobTitle HireDate);
informat Hire_Date date9.;
infile Emp dsd ;
input EmployeeID FirstName $ LastName $ Gender $ Salary JobTitle $ Country $ HireDate ;

if find(Job_Title, 'Sales Rep', "i") > 0 and Country eq 'AU';

format Salary dollar8. HireDate mmddyy10.;
run;

Title 'Listing of Sales Representatives in Australia';
Proc print data = learn.Emp;
run;
PG

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19
Using the if-statement after input-statement should solve the problem. The input-statement fills the variables.
PaigeMiller
Diamond | Level 26

 it's not working.

 

What's not working? Can you show us the SASLOG? If you are getting the wrong results, can you explain what is wrong?

 

Also, you are missing the DATA command at the beginning of your DATA step and a semi-colon or two.

--
Paige Miller
PGStats
Opal | Level 21

The condition should be evaluated AFTER the variables get a value. CONTAINS is only for WHERE and SQL.

 

libname learn '/home/XXX/learn/';

Filename Emp '/home/XXX/learn/emp.csv';
Data learn.Emp (keep = EmployeeID FirstName LastName Salary JobTitle HireDate);
informat Hire_Date date9.;
infile Emp dsd ;
input EmployeeID FirstName $ LastName $ Gender $ Salary JobTitle $ Country $ HireDate ;

if find(Job_Title, 'Sales Rep', "i") > 0 and Country eq 'AU';

format Salary dollar8. HireDate mmddyy10.;
run;

Title 'Listing of Sales Representatives in Australia';
Proc print data = learn.Emp;
run;
PG
Dublin187
Calcite | Level 5

Thank you for your help, your solution worked! 🙂

have a lovely day,

 

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
  • 4 replies
  • 1169 views
  • 2 likes
  • 4 in conversation