From a SAS program, I've generated a format file (formats.sas7bcat) that applies values to a given SAS dataset. For the dataset, in a given column, the values will be reformatted. For example, for a column 'PAYMENT' with given values of {'1', '2', '3', '4'} the values will be reformatted to something like {'credit card', 'cash', 'check', 'other'}.
To export the translated dataset I've done:
proc export
data = temp_lib.data1
outfile = /*file location & filename.csv*/
label
dbms = CSV
replace;
putnames = yes;
run;
I have 100+ formats. Instead of exporting the translated datasets, how would I go about exporting only the formats to a csv file? Something like:
variable, value, label
PAYMENT, 1, 1='credit card'
PAYMENT, 2, 2='cash'
PAYMENT, 3, 3='check'
PAYMENT, 4, 4='other'
other variable, other value, other label...
Pipe them to a data set? That same data set can then be imported back in
*pipe data to a file;
proc format cntlout = myFormats;
run;
proc export data=myFormats outfile='/folders/myfolders/myFOrmats.csv' dbms=csv replace;run;
*to recreate the formats from the data set;
proc format cntlin = myformats;
run;
@Peter_I_SAS00 wrote:
From a SAS program, I've generated a format file (formats.sas7bcat) that applies values to a given SAS dataset. For the dataset, in a given column, the values will be reformatted. For example, for a column 'PAYMENT' with given values of {'1', '2', '3', '4'} the values will be reformatted to something like {'credit card', 'cash', 'check', 'other'}.
To export the translated dataset I've done:
proc export
data = temp_lib.data1
outfile = /*file location & filename.csv*/
label
dbms = CSV
replace;
putnames = yes;
run;
I have 100+ formats. Instead of exporting the translated datasets, how would I go about exporting only the formats to a csv file? Something like:
variable, value, label
PAYMENT, 1, 1='credit card'
PAYMENT, 2, 2='cash'
PAYMENT, 3, 3='check'
PAYMENT, 4, 4='other'
other variable, other value, other label...
Pipe them to a data set? That same data set can then be imported back in
*pipe data to a file;
proc format cntlout = myFormats;
run;
proc export data=myFormats outfile='/folders/myfolders/myFOrmats.csv' dbms=csv replace;run;
*to recreate the formats from the data set;
proc format cntlin = myformats;
run;
@Peter_I_SAS00 wrote:
From a SAS program, I've generated a format file (formats.sas7bcat) that applies values to a given SAS dataset. For the dataset, in a given column, the values will be reformatted. For example, for a column 'PAYMENT' with given values of {'1', '2', '3', '4'} the values will be reformatted to something like {'credit card', 'cash', 'check', 'other'}.
To export the translated dataset I've done:
proc export
data = temp_lib.data1
outfile = /*file location & filename.csv*/
label
dbms = CSV
replace;
putnames = yes;
run;
I have 100+ formats. Instead of exporting the translated datasets, how would I go about exporting only the formats to a csv file? Something like:
variable, value, label
PAYMENT, 1, 1='credit card'
PAYMENT, 2, 2='cash'
PAYMENT, 3, 3='check'
PAYMENT, 4, 4='other'
other variable, other value, other label...
You may want to consider learning about the proc fromat CNTLOUT option to create a data set from the definitions. The output data set would have the format name, the start and end values(for ranges) and the value label plus some other stuff like whether it is a character value, multilabel, informat (invalue) or format, has an "other" range defined and such.
Your target CSV is also missing something unless you have 1) absolutely no formats with ranges of values (missing one end of the range) or 2) no formats for missing values.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: