SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
jmoore168
Obsidian | Level 7

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

4 REPLIES 4
jklaverstijn
Rhodochrosite | Level 12

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.

Reeza
Super User

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

 

Astounding
PROC Star

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.

jmoore168
Obsidian | Level 7

Thanks everyone! I was almost too embarassed to ask.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

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
  • 4 replies
  • 2468 views
  • 5 likes
  • 4 in conversation