BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Marian_2127
Calcite | Level 5

Hi all!

I have lots of numbers to infile - some of them have commas in it, some don't. Also, they don't have the same length.
For example:

x = 227

y = 99

z = 1033,97

If I try to use stuff like this:

price = input(scan(_infile_,21,'3B'x,'m'),5.2);

or

price = input(scan(_infile_,21,'3B'x,'m'),comma5.2);

then usually it results in:

x = 2.27

y = 0.99

z = 1033.97

If I take

price = input(scan(_infile_,21,'3B'x,'m'),best.);

price = input(scan(_infile_,21,'3B'x,'m'),5.);

x and y are fine, but the .97 of z is missing.

I really read a lot but still couldn't find a real solution yet.

I'm sure there is a better way than this:

price= upcase(compbl(scan(_infile_,21,'3B'x,'m')));

price1= scan(price,1, ',' )

price2 = scan(price,2, ',' )

price3 = 0||'.'||price2

price = price1+price3

If just somebody could tell me?

Thanks a lot!

1 ACCEPTED SOLUTION

Accepted Solutions
LinusH
Tourmaline | Level 20

Sorry, numx. should do the work.

Data never sleeps

View solution in original post

6 REPLIES 6
LinusH
Tourmaline | Level 20

comma.

Data never sleeps
Reeza
Super User

Is the comma supposed to be a decimal, french notation?

If so could you use the translate function to get it to be a period and then read in as a standard number?

Astounding
PROC Star

Hmmm ... I'm not sure you matched up the example 100%.  If you tried reading 1033.97 with a comma5.2 informat, you should have gotten 1033.9.  At any rate, let's start with the rules.

If the data you are reading contains 3 characters, you can still use a comma5. informat.  Your informat is allowed to be wider than the number of incoming characters.

The comma family of informats is correct.

Don't add .2 at the end of the informat.  As you have seen by getting 0.99, .2 is an instruction that says, "See if the incoming string contains a decimal point.  If it does, use it.  But if there is no decimal point, assume that the last two digits read belong after the decimal point."

The bottom line is that you need to find the largest number of characters you will need to read.  That number of characters includes everything (decimal point, negative sign, digits before as well as digits after the decimal point).  If it is 8, for example, use:

price = input(scan(_infile_, 21, '3B'x, 'm'), comma8.);

Good luck.

Marian_2127
Calcite | Level 5

@LinusH: That's not working.


@Reeza: The comma is supposed to be a decimal, german notation, yes
I think your suggestion might work but it seems still a little like 'MacGyvering'. I'm sure there is a more official way....


@Astounding: Of course you are right and the 1033.97 would have been a 1033.9 with a comma5.2.

About your idea: Unfortunately, using comma8. doesn't work either as my numbers don't contain a decimal point but a decimal comma.

So the 1033.97 becomes a 103397.

Still thankful for any further ideas

LinusH
Tourmaline | Level 20

Sorry, numx. should do the work.

Data never sleeps
Marian_2127
Calcite | Level 5

Perfect! Thanks a lot!

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!

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
  • 6 replies
  • 1053 views
  • 0 likes
  • 4 in conversation