DATA Step, Macro, Functions and more

Deleting the first letter of a variable

Accepted Solution Solved
Reply
Contributor
Posts: 23
Accepted Solution

Deleting the first letter of a variable

[ Edited ]

Hello,

 

I would like to delete the first variable of the values of the variable CONTEST:

 

(Package_ID= identification number for each package / CONT_CD=unique code for the contents in the package)

 

--------------------------------------

Package_ID    CONT_CD

1001                 XA123

1002                 XA225

1003                 YA336

---------------------------------------

 

I would like to simply get ride of the first letter of the Variable CONT_CD so it looks like the following:

 

--------------------------------------

Package_ID    CONT_CD

1001                 A123

1002                 A225

1003                 A336

---------------------------------------

 

I have tried the following,,

 

data w.package_want set w.package;

CONT_CD = SUBSTR(2,5) in CONT_CD;

RUN;

 

but I am getting an error.

 

Any advice or help would be really helpful.

 

Thank you.

 

 

 


Accepted Solutions
Solution
‎07-20-2016 09:49 PM
Super Contributor
Posts: 408

Re: Please Help: deleting the first letter of a variable

Hi,

 

There are a few issues with your code.

 

 

CONT_CD = SUBSTR(2,5) in CONT_CD;

is not correct syntax. Is this valid in some other language (just curious)? Better would be:

 

 

 

CONT_CD = SUBSTR(CONT_CD,2,5);

But in case the variable CONT_CD is only 5 positions long, this could give messages about an invalid third argument because you reach beyond the end of the string. A safe approach is simply ommiting the third argument, as that indicates "to the end".

 

CONT_CD = SUBSTR(CONT_CD,2);

 

Hope this helps,

- Jan.

 

View solution in original post


All Replies
Trusted Advisor
Posts: 1,204

Re: Please Help: deleting the first letter of a variable

Hi,

 

Please try this.

 

data want;
set have;
substr(strip(CONT_CD),1,1)='';
run;

Solution
‎07-20-2016 09:49 PM
Super Contributor
Posts: 408

Re: Please Help: deleting the first letter of a variable

Hi,

 

There are a few issues with your code.

 

 

CONT_CD = SUBSTR(2,5) in CONT_CD;

is not correct syntax. Is this valid in some other language (just curious)? Better would be:

 

 

 

CONT_CD = SUBSTR(CONT_CD,2,5);

But in case the variable CONT_CD is only 5 positions long, this could give messages about an invalid third argument because you reach beyond the end of the string. A safe approach is simply ommiting the third argument, as that indicates "to the end".

 

CONT_CD = SUBSTR(CONT_CD,2);

 

Hope this helps,

- Jan.

 

Contributor
Posts: 23

Re: Please Help: deleting the first letter of a variable

Thank you very much for your help!

☑ This topic is SOLVED.

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

Discussion stats
  • 3 replies
  • 806 views
  • 5 likes
  • 3 in conversation