Help using Base SAS procedures

substr command

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

substr command

Hello I am just trying to figure out a simple substr command:

data a;

input A B @@;

datalines;

123 ABCD

;

run;

data a; set a ;

if substr(B,1,1) = "A" then type ="S";

else type='K';

T = substr(B,1,2);

run;

Not sure why this code is not working, it just always defaults to K. Any ideas?


Accepted Solutions
Solution
‎07-05-2013 09:12 PM
Respected Advisor
Posts: 3,902

Re: substr command

Run the first data step only and then check what you've actually got in table 'a'.

Also: Always read the SAS log as it gives you valuable information, eg:

NOTE: Invalid data for B in line 18 5-8.

View solution in original post


All Replies
Solution
‎07-05-2013 09:12 PM
Respected Advisor
Posts: 3,902

Re: substr command

Run the first data step only and then check what you've actually got in table 'a'.

Also: Always read the SAS log as it gives you valuable information, eg:

NOTE: Invalid data for B in line 18 5-8.

Occasional Contributor
Posts: 9

Re: substr command

Thanks Patrick, I'm still a novice to SAS, I'll take your advice in running parts of the code each time.  Made the correction and it worked fine:

data a;

input A B $ @@;

datalines;

123 ABCD

;

run;

data a; set a ;

if substr(B,1,1) = "A" then type ="S";

else type='K';

T = substr(B,1,2);

run;

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 158 views
  • 0 likes
  • 2 in conversation