BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Seb_A_Sanders
Calcite | Level 5

Hi,

 

I have the following template I have to comply with:

 

CompanyXXCurrencyGBPTr date today-1Process date today-1
NominalDivisionCurrencysub acAmountTrans codeSelectNarrativeDate (optional)
NumericCharacterCharacterCharacterNumericNumeric   

 

(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:

 

NominalDivisionCurrencysub acAmountTrans codeSelectNarrativeDate (optional)
12345X1GBPX1231234   

 

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:

 

CompanyXXCurrencyGBPTr date today-1Process date today-1

 

above the first line via excel to produce:

 

CompanyXXCurrencyGBPTr date 21/10/18Process date 21/10/18
NominalDivisionCurrencysub acAmountTrans codeSelectNarrativeDate (optional)
12345X1GBPX1231234   

 

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.

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

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;

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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;
Oligolas
Barite | Level 11

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 -

s_lassen
Meteorite | Level 14

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;

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 3 replies
  • 1929 views
  • 0 likes
  • 4 in conversation