BookmarkSubscribeRSS Feed
knobwan
Calcite | Level 5

Good morning !

How to convert a field which has the format of   MGBYTES.    to bytes (only numbers) ?

 

Sometimes i have entries like "100k",  sometimes entries like "35M" and I  would like to standardize all values to Bytes (only numbers).

Any ideas please ?

Thanks !!

 

6 REPLIES 6
Tom
Super User Tom
Super User

Look at the proc contents of the dataset with that variable.  Is it numeric or character?  If it is numeric with the SIZEKMG format attached to it then just use a different format for displaying the values.

If it is character do you want to make a new variable that has a number in it? Or change the strings in the current variable?  If the latter is the variable defined long enough to store the longer strings it will require?

 

Kurt_Bremser
Super User

Separate the string into a number and the "unit" part with the help of the NOTDIGIT function.

INPUT the number, and use an informat to convert the unit to a multiplicator.

 

By supplying example data in usable form (data step with datalines), you make it easy for us to come up with code suggestions.

knobwan
Calcite | Level 5

Proc contents shows this :

 

VARIABLE TYPE  LEN  FORMAT
-------- ----- --- ---------
SIZEA     NUM   5   MGBYTES.

I'm basically printing this variable with put in the output file:

DATA _NULL_;
SET ;
FILE FOUT NOPRINT ;

IF _N_ = 1 THEN DO ;
  PUT 'SYSTEM|'
      'SIZE|';

PUT SYSTEM '|' SIZEA '|'; RUN;

I also checked the NOTDIGIT.. but my sas experience is limited. No clue on how to use to have the number converted to bytes.

 

 

knobwan
Calcite | Level 5

The code didn't end in error. But issue a warning and printed the same values... 300K, 50M

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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