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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 28439 views
  • 7 likes
  • 3 in conversation