Hello expert,
Please, I want To export data to .txt file format
if variable =4567.345 then I want to get it in .txt file with this format
data toto;
v1=1111.12;
V2='ok';
vn=123456.756;
run;
.txt file
v1;v2;v3
1111,12;ok;123456,756
aim : go from a numerical variable yyyyyy.aaabbb and getting yyyyyy,aaabbb
This will be for many variables.
Thank you
If I do this:
data mydata;
input dept : $10. jan : numx. feb : numx8.2 mar comma8.3;
datalines;
hoes 4344 35555 26664
ousewares 3777 48886 79998
pliances 5311 71223 41333
;
PROC EXPORT DATA= mydata OUTFILE= testtxtfile dbms= tab replace;
PUTNAMES=YES;
run;
I get testtxtfile that looks like:
dept jan feb mar hoes 4344 355.55 26.664 ousewares 3777 488.86 79.998 pliances 5311 712.23 41.333
But then if you go look in the log where the PROC Export ran you will see this:
data _null_;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
%let _EFIREC_ = 0; /* clear export record count macro variable */
file 'TESTTXTFILE' delimiter='09'x DSD DROPOVER lrecl=32767;
if _n_ = 1 then /* write column names or labels */
do;
put
"dept"
'09'x
"jan"
'09'x
"feb"
'09'x
"mar"
;
end;
set MYDATA end=EFIEOD;
format dept $10. ;
format jan best12. ;
format feb best12. ;
format mar best12. ;
do;
EFIOUT + 1;
put dept $ @;
put jan @;
put feb @;
put mar ;
;
end;
if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
if EFIEOD then call symputx('_EFIREC_',EFIOUT);
run;
If you then replace your Proc Export with that code, and change
format mar best12.
to
format mar numx8.3.
I get this output:
dept jan feb mar hoes 4344 355.55 26,664 ousewares 3777 488.86 79,998 pliances 5311 712.23 41,333
which is what I think you want.
Roundabout, and I'm sure there is a better way, but it gets there.
If I do this:
data mydata;
input dept : $10. jan : numx. feb : numx8.2 mar comma8.3;
datalines;
hoes 4344 35555 26664
ousewares 3777 48886 79998
pliances 5311 71223 41333
;
PROC EXPORT DATA= mydata OUTFILE= testtxtfile dbms= tab replace;
PUTNAMES=YES;
run;
I get testtxtfile that looks like:
dept jan feb mar hoes 4344 355.55 26.664 ousewares 3777 488.86 79.998 pliances 5311 712.23 41.333
But then if you go look in the log where the PROC Export ran you will see this:
data _null_;
%let _EFIERR_ = 0; /* set the ERROR detection macro variable */
%let _EFIREC_ = 0; /* clear export record count macro variable */
file 'TESTTXTFILE' delimiter='09'x DSD DROPOVER lrecl=32767;
if _n_ = 1 then /* write column names or labels */
do;
put
"dept"
'09'x
"jan"
'09'x
"feb"
'09'x
"mar"
;
end;
set MYDATA end=EFIEOD;
format dept $10. ;
format jan best12. ;
format feb best12. ;
format mar best12. ;
do;
EFIOUT + 1;
put dept $ @;
put jan @;
put feb @;
put mar ;
;
end;
if _ERROR_ then call symputx('_EFIERR_',1); /* set ERROR detection macro variable */
if EFIEOD then call symputx('_EFIREC_',EFIOUT);
run;
If you then replace your Proc Export with that code, and change
format mar best12.
to
format mar numx8.3.
I get this output:
dept jan feb mar hoes 4344 355.55 26,664 ousewares 3777 488.86 79,998 pliances 5311 712.23 41,333
which is what I think you want.
Roundabout, and I'm sure there is a better way, but it gets there.
See next link with hope it will help you:
https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/Decimal-points-to-commas/td-p/87649
You could use something like:
data toto;
v1=1111.12;
V2='ok';
vn=123456.756;
output;
v1=2222.23;
V2='notok';
vn=654321.657;
output;
run;
proc sql noprint;
select name,name
into :names separated by ';',
:vars separated by ' ";" '
from dictionary.columns
where libname=upcase('work') and
memname=upcase('toto')
;
quit;
data _null_;
set toto;
file "c:\art\test.txt";
put "&names.";
put &vars.;
run;
HTH,
Art, CEO, AnalystFinder.com
@ll: Thank you all for your answers.
Great
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.