Keep only first four characters

Reply
Occasional Contributor
Posts: 11

Keep only first four characters

[ Edited ]

Hi,

 

I have a simple problem I want to solve.  I have a column where the output is, ex. 1303/0000/1. But I only need '1303' that I'll eventually convert into a currency value later.  

 

Current output

 

SALE Npv.png

 

Desired output

 

STATUS_CD

SALES_NPV

S04

1302

S04

1485

S04

0967

Super Contributor
Posts: 508

Re: Keep only first four characters

Posted in reply to jmoore168

For this they have invented the SUBSTR function:

 

SALES_NPV = SUBSTR(SALES_NPV, 1, 4);

This function is very basic. I would recommend you have a look at the other SAS functions as well.

 

Regards,

- Jan.

Super User
Posts: 22,529

Re: Keep only first four characters

Posted in reply to jmoore168

Since you have the / as a delimiter you can also use the SCAN() function.

 

Super User
Posts: 6,371

Re: Keep only first four characters

Posted in reply to jmoore168

I can name that tune with 0 functions:

 

data want;

length sales_npv $ 4;

set have;

run;

 

There's only room to save the first four characters, once the length has been defined.

Occasional Contributor
Posts: 11

Re: Keep only first four characters

Posted in reply to jmoore168

Thanks everyone! I was almost too embarassed to ask.

Ask a Question
Discussion stats
  • 4 replies
  • 118 views
  • 5 likes
  • 4 in conversation