BookmarkSubscribeRSS Feed
YangM90
Fluorite | Level 6

Hello SAS Forum,

 

I have an excel data file, where the columns are full of numbers. The numbers are seperated by columns; e.g. 1,356,292 (meaning approximately 4/3). But when I import the file via proc import:

 

proc import datafile = data
  out=data
  dbms=xlsx
  replace;
run;


SAS reads this as 1356292.

 

Is there an easy step to convert it "back" to the original format? 🙂

Best regards,


4 REPLIES 4
Kurt_Bremser
Super User

That number can never be equivalent to ~1.3. It was, is, and will always be 1356292. You cannot have more than one decimal point (either represented by the period or the comma, depending on locale) in a number.

Otherwise, how could you know it's not 1356.292?

andreas_lds
Jade | Level 19

The problem is, that "1,356,292" is only a valid number if the comma is treated as thousands-separator, which is exactly what SAS does. If the data would be stored in a proper file-format for holding data (like csv), you could write code to fix the strange format, but with excel post-processing the data is the only option you have. And for that rules must exists defining the meaning of the comma at its various positions.

Patrick
Opal | Level 21

Even with Excel there is a difference between how a number "prints" formatted and what's stored internally.

Patrick_0-1592302769231.png

 

SAS reads the internal value and then applies a standard SAS format for printing.

 

You can always change the format also in SAS.

On-the-fly within a single Procedure

data test;
  myvar=1356292;
  output;
  stop;
run;

proc print data=test;
  format myvar comma16.;
  var myvar;
run;

Patrick_0-1592303014079.png

Or permanently attached to the variable in the table:

proc datasets lib=work nolist;
  modify test;
    format myvar comma16.;
  run;
quit;

proc print data=test;
run;

 Patrick_1-1592303028175.png

 

Reeza
Super User

The numbers are seperated by columns; e.g. 1,356,292 (meaning approximately 4/3). But when I import the file via proc import:

Excel is storing that as one million three hundred fifty six thousand two hundred ninety two, not 4/3. 

 

If that value is actually comma separated numbers then you'll need to format that column as text within Excel. 

 

Unfortunately when reading from Excel it's very difficult to force the types when importing data, if you're reading from a different source such as CSV, XML or JSON. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 1993 views
  • 2 likes
  • 5 in conversation