Wednesday, March 9, 2011

Output ASCII data files in SAS


/*ASCII data seperated by space */
data _null_;
      set sasuser.credit;
      file 'c:\sasdata\credit.txt';
      put Account Name Type Transaction;
run

Or we can use:

filename mydata 'c:\sasdata\credit.txt';
data _null_;
      set sasuser.credit;
      file mydata;
      put Account Name Type Transaction;
run;


The result is:
1118 ART CONTUCK D 57.69
2287 MICHAEL WINSTONE D 145.89
6201 MARY WATERS C 45.00
7821 MICHELLE STANTON A 304.45
6621 WALTER LUND C 234.76
1086 KATHERINE MORRY A 64.98
0556 LEE McDONALD D 70.82
7821 ELIZABETH WESTIN C 188.23
0265 JEFFREY DONALDSON C 78.90
1010 MARTIN LYNN D 150.55

/*ASCII data seperated by "," */
data _null_;
      set sasuser.credit;
      file 'c:\sasdata\credit1.txt';
      put Account "," Name "," Type "," Transaction;
run;

The result is:
1118 ,ART CONTUCK ,D ,57.69
2287 ,MICHAEL WINSTONE ,D ,145.89
6201 ,MARY WATERS ,C ,45.00
7821 ,MICHELLE STANTON ,A ,304.45
6621 ,WALTER LUND ,C ,234.76
1086 ,KATHERINE MORRY ,A ,64.98
0556 ,LEE McDONALD ,D ,70.82
7821 ,ELIZABETH WESTIN ,C ,188.23
0265 ,JEFFREY DONALDSON ,C ,78.90
1010 ,MARTIN LYNN ,D ,150.55

/* Create a data file with multiple lines per record */
data _null_;
      set sasuser.credit;
      file 'c:\sasdata\credit2.txt';
      put Account;
      put  Name Type Transaction;
run; 

The result is:
1118
ART CONTUCK D 57.69
2287
MICHAEL WINSTONE D 145.89
6201
MARY WATERS C 45.00
7821
MICHELLE STANTON A 304.45
6621
WALTER LUND C 234.76
1086
KATHERINE MORRY A 64.98
0556
LEE McDONALD D 70.82
7821
ELIZABETH WESTIN C 188.23
0265
JEFFREY DONALDSON C 78.90
1010
MARTIN LYNN D 150.55

No comments:

Post a Comment