data _null_; /* To enclose values of the numeric variable FEE in quotes, we must convert it into a character variable. This character variable will be called CHARFEE. 10 columns of width will be reserved for the digits, commas, and dollar sign, while 2 additional columns are necessary for the quotation marks. */ length CharFee $ 12; set prog2.visits; /* The PUT function is used to convert the numeric values of FEE into character values of CHARFEE. The PUT function is described in section five of chapter five. */ CharFee=put(fee,dollar10.2); /* The INDEX function is used to determine whether the value of CHARFEE contains a comma. The INDEX function is described in section two of chapter five. If the value of CHARFEE contains a comma, left align the value using the LEFT function, remove trailing blanks using the TRIM function, and surround the remaining characters with double quotes using the QUOTE function. The LEFT and TRIM functions are described in section two of chapter five. */ if index(CharFee,',') gt 0 then CharFee=quote(trim(left((CharFee)))); /* The DLM= option and the DSD option are not available in the FILE statement in version 6. */ file 'visits.csv'; /* Relative pointer control must be used to move the output pointer one position to the left after writing each variable value. Remember that, by default, list input causes the PUT statement to write a variable value, insert a single blank, and then write the next value. Commas are inserted manually using a quoted string. */ put ID +(-1) ',' Date : mmddyy10. +(-1) ',' CharFee; run; /* The FILE statement is applicable to the Windows and UNIX operating environments. OS/390 users should use: file '.prog2.rawdata(visits)'; */ proc fslist fileref='visits.csv'; run; /* The PROC FSLIST statement is applicable to the Windows and UNIX operating environments. OS/390 users should use: proc print fileref='.prog2.rawdata(visits)'; run; */