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

For one of the research studies I work on, we are meant to upload data to the National Data Archive (NDA). To this end, in SAS 9.4 we are trying to create several CSV files - one for each of the survey instruments used in our interviews. NDA uploads require a row at the top of the file with information for their system to read in (in this case, A1="ndar_subject" and B1=1), the second row is the variable names, and the rest is the data.

One solution I hoped for would be to print data labels AND variable names, where we assign variable1="ndar_subject" and variable2="1" for labels and leave the rest blank. We tried using a title statement in conjunction with ODS CSVALL, but that only provided us with the cell A1 requirement.

Another thought would be to somehow insert a row into the CSV with A1="ndar_subject" and B1=1 and then continue with a PROC PRINT.

Any solution suggestions are welcome!

1 ACCEPTED SOLUTION

Accepted Solutions
andreas_lds
Jade | Level 19

I really like RWI, but for this task it is a bit too much. The example uses sashelp.class. Tested with SAS 9.4m5.

 

ods csvall file="class.csv";

proc odstext;
   p 'A1="ndar_subject" and B1=1';
run;

proc print data=sashelp.class noobs;
run;

ods csvall close;

View solution in original post

4 REPLIES 4
andreas_lds
Jade | Level 19

I really like RWI, but for this task it is a bit too much. The example uses sashelp.class. Tested with SAS 9.4m5.

 

ods csvall file="class.csv";

proc odstext;
   p 'A1="ndar_subject" and B1=1';
run;

proc print data=sashelp.class noobs;
run;

ods csvall close;
Tom
Super User Tom
Super User

Writing a CSV file is trivial so writing an extra line at the top of it is going to be very easy.  But it is not at all clear what you mean.

What you seem to be describing is a file like this:

"A1=""ndar_subject""",B1=1
var1,var2
A,1
B,2
C,3

But somehow that seems not reasonable.

 

 

Please show an example of the file want to create.

 

Here is how you could make a CSV file from SASHELP.CLASS with an extra line at the top with any text you want.

filename csv 'myfile.csv';
data _null_;
  file csv;
  put 'This is the header row';
run;
proc transpose data=sashelp.class(obs=0) out=names;
  var _all_;
run;
data _null_;
  file csv dsd mod;
  set names;
  put _name_ @;
run;
data _null_;
  file csv dsd mod;
  set sashelp.class;
  put (_all_) (+0);
run;

Result:

This is the header row
Name,Sex,Age,Height,Weight
Alfred,M,14,69,112.5
Alice,F,13,56.5,84
Barbara,F,13,65.3,98
Carol,F,14,62.8,102.5
Henry,M,14,63.5,102.5
James,M,12,57.3,83
Jane,F,12,59.8,84.5
Janet,F,15,62.5,112.5
Jeffrey,M,13,62.5,84
John,M,12,59,99.5
Joyce,F,11,51.3,50.5
Judy,F,14,64.3,90
Louise,F,12,56.3,77
Mary,F,15,66.5,112
Philip,M,16,72,150
Robert,M,12,64.8,128
Ronald,M,15,67,133
Thomas,M,11,57.5,85
William,M,15,66.5,112

 

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 16. 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
  • 4 replies
  • 864 views
  • 6 likes
  • 5 in conversation