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 !!
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?
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.
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.
Since your variable is numeric, just remove the format with
format sizea;
in the data step.
The code didn't end in error. But issue a warning and printed the same values... 300K, 50M
Please post the complete log of the step. Copy/paste it into a window opened with the </> button.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.