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

Hello, 

 

I am trying to make a code that can help me recategorize my tables. The variables that will be conditioned are: Province and City. Basically, if Province is = to Toronto and the Province is Ontario, i'd like the region to be categorized as "Toronto". If province is = to Ontario and city is NOT equal to toronto, id like region to be categorized as "outside of toronto". 

 

Here is the code I have: 

data work.tester2;

if province="ON" and city="torontp"
then
Region="Toronto";

else if province= "ON" and city^="toronto"
then Region="outside of toronto";
end;

run;

 

when I run this code, all fields go blank. 

 

Thanks

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star

Ah, you aren't reading any data in. You need a SET statement to read in an existing SAS dataset.

View solution in original post

5 REPLIES 5
SASKiwi
PROC Star

Try removing your END statement and can only be used with a matching DO statement which you don't have.

 

Check your SAS log for errors. What does it say?

JibJam221
Obsidian | Level 7
thanks for your help, when I remove the END, all columns delete and I am left with three blank columns: Province, City, and Region. I'm not sure what is going wrong, but there is no errors or notes in the log
SASKiwi
PROC Star

Ah, you aren't reading any data in. You need a SET statement to read in an existing SAS dataset.

JibJam221
Obsidian | Level 7
WOW good catch! Its always the little things. I appreciate your help!
JibJam221
Obsidian | Level 7
hello, quick question. I updated my code to categorize the entire dataset. Here is my code:
data work.tester4;
set work.tester4;

if province="ON" and city="Toronto" then Region="Toronto";
else if province= "ON" and city^="Toronto" then Region="Outside of Toronto";
else if province="AB" and city="Calgary" then Region="Calgary";
else if province="AB" and city^="Calgary" then Region="Outside of Calgary";
else Region="N/A";
run;

I am recieving the following error:
WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.


is this a reason for concern? The warning is highlighted as the 'run;' statement.

thanks

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 5 replies
  • 1284 views
  • 2 likes
  • 2 in conversation