BookmarkSubscribeRSS Feed
sasbanker
Calcite | Level 5

I have two Char fields with a length of 10, named "Acct" and "Derived". 

I need to test the "Acct" field, and if the value has a length of 6, and is a numeric value between 100,000 & 999,999, then copy the value to the "Derived" field.

How to code the Update statement?

Sample data looks like this:

Acct

==========

1

100

1000A

201000     ==> Copy

210000A

312456   ==> Copy

A400010

I'm a newbie just learning, so please be specific in your response.i

3 REPLIES 3
naveen20jan
Obsidian | Level 7

Hi ,

You can try the below approch ;

data want  ;

set have  ;

if notdigit(acct) = 0 and lenght(acct)  = 6 and  100000 =<acct >=999999 then  derived = acct ;

run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Just to note, you don't actually need to check the length there:

if notdigit(acct) = 0 and 100000 =<acct >=999999 then  derived = acct ;

As anything not between the given upper and lower includes those with a length ne 6.

Ksharp
Super User

data have;

input acct $;

cards;

1

100

1000A

201000  

210000A

312456 

A400010

;

run;

data want ;

set have;

length derived $ 10;

if 100000<=input(acct,?? best32.)<=999999 then derived=acct;

run;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 751 views
  • 0 likes
  • 4 in conversation