BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
LineMoon
Lapis Lazuli | Level 10

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

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
HB
Barite | Level 11 HB
Barite | Level 11

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.

 

View solution in original post

5 REPLIES 5
HB
Barite | Level 11 HB
Barite | Level 11

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.

 

LineMoon
Lapis Lazuli | Level 10
Thank you.
That's exact
art297
Opal | Level 21

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

 

LineMoon
Lapis Lazuli | Level 10

@ll: Thank you all for your answers.

Great

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 890 views
  • 3 likes
  • 4 in conversation