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 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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1593 views
  • 2 likes
  • 4 in conversation