BookmarkSubscribeRSS Feed
sbrighenti
Calcite | Level 5

Hello,

 

I am currently working in DiStudio and am reading in a SAS dataset that has a numeric value. I'm trying to create a 'verification' job that looks to see the number of digits before and after the decimal and flag any that are not accurate. I've done this before, but the field was a character field and not numeric.

 

For example, we have a table of values and the ones that appear in a numeric column are as follows:

1.1230

1.784

1.1487

 

We want to find all decimals without four decimals (ie 1.784) However, when I do (LENGTH(SCAN(PUT(X,best.),2,'.')) ^= 4, it flags both 1.784 and 1.1230 since best drops the trailing zero.

Would somebody be able to help me figure out how I can find the digits after the decimal place in the WHERE tab of DiStudio?

3 REPLIES 3
SuryaKiran
Meteorite | Level 14

Don't convert to numeric, extract the number before and after decimal and find the length for that characters.

length(strip(scan(val,1,'.')))=1 and  length(strip(scan(val,2,'.')))=3
Thanks,
Suryakiran
SuryaKiran
Meteorite | Level 14

Also you can try perl regular expression for this type of matching.

 

prxmatch("/^\d{1}\.\d{3}$/",strip(val))=1

^           - Beginning 

\d{1}     - one digit

\. (\dot)  - escape special character { .

\d{3}      - 3 digits 

$           - End of line

Thanks,
Suryakiran
Patrick
Opal | Level 21

Once you've read the source string into a numerical variable there is no telling if the source string was 1.2 or 1.2000

It's numerically the same and will be stored internally the same. It has nothing to do with formats.

 

To check the digits of the source string you need to read the data as character. With DIS you can do so by defining a character informat for the External File Metadata. After that use the same approach as in the past. You can always later on convert the character variable to a numeric one via an expression like input(<charvar>, best32.)

sas-innovate-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1469 views
  • 3 likes
  • 3 in conversation