Hi,
I have the following template I have to comply with:
Company | XX | Currency | GBP | Tr date | today-1 | Process date | today-1 | |
Nominal | Division | Currency | sub ac | Amount | Trans code | Select | Narrative | Date (optional) |
Numeric | Character | Character | Character | Numeric | Numeric |
(Variable types listed in row 3 - "Select", "Narrative" & "Date" are blank and filled in by end-users)
I produce a file currently with row 2 as the header and the required data in the fields and I export as a CSV, then manually add the top row to each file, manually filling in the fields highlighted in bold italic (on row 1) before distributing the files to the end users, who fill in the blank columns.
I would like to create a file that has both headers on the export file so the manual step is avoided.
Any concepts or solutions would be appreciated.
EDIT:
I think there was some confusion, the current table is exported:
Nominal | Division | Currency | sub ac | Amount | Trans code | Select | Narrative | Date (optional) |
12345 | X1 | GBP | X | 123 | 1234 |
The Italic was an example of the data type in the field, it doesn't get written to the table.
Then I have to manually add:
Company | XX | Currency | GBP | Tr date | today-1 | Process date | today-1 |
above the first line via excel to produce:
Company | XX | Currency | GBP | Tr date | 21/10/18 | Process date | 21/10/18 | |
Nominal | Division | Currency | sub ac | Amount | Trans code | Select | Narrative | Date (optional) |
12345 | X1 | GBP | X | 123 | 1234 |
This is obviously written to file with the comma delimiter, I've just pasted it in table form for ease of reading.
Hope this clarifies matters, thanks for the responses so far.
I see two possibilities. The first is to modify the code generated by PROC EXPORT (pressing F4 or issuing the RECALL command after submitting the PROC EXPORT statements should get you the generated code), and add the extra header line in the code (drop the original PROC EXPORT statements).
The other is to modify the file you have generated, e.g.
proc export data=mydata outfile=file1 dbms=csv;
run;
data _null_;
infile file1;
file file2;
if _N_=1 then
/* code to put extra header goes here */;
input;
put _infile_;
run;
That is not a CSV file. Please do not type random data formats with standard sources.
As for how you do this, you will need to manually put out data to a plain text file as it is not a standard file format.
Maybe something like:
data _null_; file "want.txt"; put ...; run;
Hi,
simply add a label to your variables, you could add the variable type in curly braces for example:
data test;
Nominal=1;
Division='bla';
label Nominal = 'Nominal {Numeric}'
Division = 'Division {Character}'
;
RUN;
PROC EXPORT DATA= WORK.Test
OUTFILE= "c:\temp\test.csv"
DBMS=CSV LABEL REPLACE;
PUTNAMES=YES;
RUN;
- Cheers -
I see two possibilities. The first is to modify the code generated by PROC EXPORT (pressing F4 or issuing the RECALL command after submitting the PROC EXPORT statements should get you the generated code), and add the extra header line in the code (drop the original PROC EXPORT statements).
The other is to modify the file you have generated, e.g.
proc export data=mydata outfile=file1 dbms=csv;
run;
data _null_;
infile file1;
file file2;
if _N_=1 then
/* code to put extra header goes here */;
input;
put _infile_;
run;
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 25. 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.