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

data code2;
input country$ 10.;
datalines;
IndiaIN
AmericaAM
IndiaIN
canadaCA
FranceFR
IndiaIN
;
run;
proc print data=code;
run;

data test4;
set code2;
Position=find(country,"IN");
/*am=find(country,"AM"); */
/*ca=find(country,"CA");
fr=find(country,"FR");*/
Ccode=substr(country,Position);
run;

 

 

expecting all country code under Ccode variable.

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @Ajayvit 

 

Are you asking for 

 



data code2;
input country$ 10.;
datalines;
IndiaIN
AmericaAM
IndiaIN
canadaCA
FranceFR
IndiaIN
;
run;


data test4;
set code2;
Ccode=substr(country,length(country)-2+1);
run;

 Or

Ccode=substr(country,length(country)-1);

View solution in original post

5 REPLIES 5
novinosrin
Tourmaline | Level 20

Hi @Ajayvit 

 

Are you asking for 

 



data code2;
input country$ 10.;
datalines;
IndiaIN
AmericaAM
IndiaIN
canadaCA
FranceFR
IndiaIN
;
run;


data test4;
set code2;
Ccode=substr(country,length(country)-2+1);
run;

 Or

Ccode=substr(country,length(country)-1);
Ajayvit
Obsidian | Level 7
Dear,

Thank you for your reply. I am getting same o/p what i was expecting.
Tom
Super User Tom
Super User

Do all of the values have the country code as the last two characters?

code = substr(country,length(country)-1);
country=substr(country,1,length(country)-2);

Or do you need to hunt for them?

Reeza
Super User
Are you sure you don't have a delimiter? Can you view the file in NotePad++ and show a screenshot with invisible characters shown? It would be bad practice to store data like, not that it hasn't happened before, but it's so bad that I would expect a different approach to be available.
Ajayvit
Obsidian | Level 7
Dear Reeza,

Thank you for replying.
None of the observation is having delimiter.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1283 views
  • 3 likes
  • 4 in conversation