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;
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;
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.
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;
Thank you for your help, your solution worked! 🙂
have a lovely day,
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.