Hello,
I use enterprise guide (for coding not point and click) and I was looking to export a large dataset into a CSV file.
I was going to use a proc export as I need to use the delimiter '|'. An issue I have is I want all the character variables to be output within double quotations (" ") and the numeric/date variables to be output without them.
Is there a quick way of achieving this?
Try this, I did not make the name row.
40 data _null_;
41 set sashelp.class;
42 file log dlm='|';
43 put (_all_)(:);
44 format _character_ $quote128.;
45 run;
"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
Try this, I did not make the name row.
40 data _null_;
41 set sashelp.class;
42 file log dlm='|';
43 put (_all_)(:);
44 format _character_ $quote128.;
45 run;
"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
I added NAME row not quote. Notice that the absence of DSD will make that slightly different from PROC EXPORT. But with DSD the quotes are doubled and double quoted.
40 data _null_;
41 set sashelp.heart(obs=50);
42 file log dlm='|' ls=256;
43 if _n_ eq 1 then link names;
44 put (_all_)(:);
45 format _character_ $quote128.;
46 return;
47 names:
48 length _name_ $32;
49 do while(1);
50 call vnext(_name_);
51 if upcase(_name_) eq '_NAME_' then leave;
52 put _name_ @;
53 end;
54 put;
55 run;
Status|DeathCause|AgeCHDdiag|Sex|AgeAtStart|Height|Weight|Diastolic|Systolic|MRW|Smoking|AgeAtDeath|Cholesterol|Chol_Status|BP_Status|Weight_Status|Smoking_Status
"Dead"|"Other"|.|"Female"|29|62.5|140|78|124|121|0|55|.|""|"Normal"|"Overweight"|"Non-smoker"
"Dead"|"Cancer"|.|"Female"|41|59.75|194|92|144|183|0|57|181|"Desirable"|"High"|"Overweight"|"Non-smoker"
"Alive"|""|.|"Female"|57|62.25|132|90|170|114|10|.|250|"High"|"High"|"Overweight"|"Moderate (6-15)"
"Alive"|""|.|"Female"|39|65.75|158|80|128|123|0|.|242|"High"|"Normal"|"Overweight"|"Non-smoker"
"Alive"|""|.|"Male"|42|66|156|76|110|116|20|.|281|"High"|"Optimal"|"Overweight"|"Heavy (16-25)"
"Alive"|""|.|"Female"|58|61.75|131|92|176|117|0|.|196|"Desirable"|"High"|"Overweight"|"Non-smoker"
"Alive"|""|.|"Female"|36|64.75|136|80|112|110|15|.|196|"Desirable"|"Normal"|"Overweight"|"Moderate (6-15)"
"Dead"|"Other"|.|"Male"|53|65.5|130|80|114|99|0|77|276|"High"|"Normal"|"Normal"|"Non-smoker"
"Alive"|""|.|"Male"|35|71|194|68|132|124|0|.|211|"Borderline"|"Normal"|"Overweight"|"Non-smoker"
If you used DSD option that will cause it. Show your program.
@data_null__ Can you explain how DOW WHILE (1) is working and what is _name_ variable?
@SAS_inquisitive DO WHILE(1); is infinite loop. Notice the LEAVE statement to exit.
_NAME_ is the value returned from CALL VNEXT. It is the name of a variable from the PDV.
Each time VNEXT is executed it returns the "next" variable in the PDV. It provides a way to iterate across the PDV. It will also return the length and type of the variable.
In some other languages it might be writen using FOR statement a list iterator.
for NAME in PDV do end
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.