BookmarkSubscribeRSS Feed
PRAVIN_JAIN
Calcite | Level 5

I am creating a text files from SAS dataset, I used BEST32. for numeric variables. But upon using this I get lot of spaces in field values in text file due to this file size is increasing a lot. How i can compess these spaces.

 

ex - 

}                       999999998 }}                          110 }                   237.877 }

 

Sample Code - 

data _null_;
set ds_1;
file 'path' DSD lrecl=15000;
put FILE_CREATE_DT +(-1) "}" COUNTRY +(-1) "}" OPEN_DT +(-1) "}" OWN_NUM BEST32. +(+1) "}"
LIMIT BEST32. +(+1) "}" BAL BEST32. +(+1) "}" OWN_NAME;
run;

4 REPLIES 4
LinusH
Tourmaline | Level 20

First create a temporary variable with the whole string you wish to PUT.

While doing so, you can the various trimming functions SAS offers, like CATS, CATX, TRIM, TRIMN, COMPRESS, LEFT etc.

Data never sleeps
Ksharp
Super User
Do NOT adding the format, just remove them.

put LIMIT +(+1) "}" BAL +(+1) "}" OWN_NAME;
ballardw
Super User

Are attempting to create a specific file type such as JSON?

 

Tom
Super User Tom
Super User

Use the : modifier to allow you to include a format specification in the PUT statement and yet still generate the result the same as if you used LIST MODE instead of FORMATTED mode.

put
 FILE_CREATE_DT +(-1) "}" 
 COUNTRY +(-1) "}" 
 OPEN_DT +(-1) "}" 
 OWN_NUM :BEST32. +(-1) "}"
 LIMIT :BEST32. +(-1) "}" 
 BAL :BEST32. +(-1) "}" 
 OWN_NAME
;

Or simply attach the format to the variable and remove the format specification from the PUT statement.

put
 FILE_CREATE_DT +(-1) "}" 
 COUNTRY +(-1) "}" 
 OPEN_DT +(-1) "}" 
 OWN_NUM  +(-1) "}"
 LIMIT  +(-1) "}" 
 BAL  +(-1) "}" 
 OWN_NAME
;
format OWN_NUM LIMIT BAL best32.;

Also since you seem to just want to generate '}' as the delimiter why not tell the FILE statement to do that?

data _null_;
  set ds_1;
  file 'path' DSD dlm='}' lrecl=15000;
  put FILE_CREATE_DT COUNTRY OPEN_DT OWN_NUM LIMIT BAL OWN_NAME;
  format OWN_NUM LIMIT BAL best32.;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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
  • 1100 views
  • 2 likes
  • 5 in conversation
OSZAR »