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

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.

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
jklaverstijn
Rhodochrosite | Level 12

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

3 REPLIES 3
stat_sas
Ammonite | Level 13

Hi,

 

Please try this.

 

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

jklaverstijn
Rhodochrosite | Level 12

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.

 

sasworker16
Calcite | Level 5

Thank you very much for your help!

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.

Register now!

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
  • 3 replies
  • 30898 views
  • 7 likes
  • 3 in conversation