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

Hi All,

I am using the following code in SAS Viya to export a sas7bdata table to a csv file:

 

PROC EXPORT 
DATA=Export.tdsr_apr2019_out
DBMS=csv
LABEL
OUTFILE='/sasshare/prd/AUDIT/BlackMESA/Export/tdsr_apr2018_export.csv'
REPLACE;

 

The problem is that this export adds quotes around the column headers and actually adds new fields. See attached file. 

I am using SAS Viya 3.4

 

In SAS EG I was able to use the import utility which worked great. Here, in SAS Studio, I need to code it which I did.

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Why did you post an XLSX file if you are trying to create a CSV file?  Do NOT use EXCEL to look at CSV files because it will corrupt the values.

 

To share an example of what was created copy the first few lines of text from the CSV file and past into the forum using the pop-up window that appears when you use the Insert Code icon on the menu bar.  (The one that looks like {i} ).

 

Why do you care if the CSV file has quotes around some of the values?  Quotes around values in a CSV should be ignored by the reader since they are just there in case the value contains the delimiter.

View solution in original post

8 REPLIES 8
Tom
Super User Tom
Super User

Why did you post an XLSX file if you are trying to create a CSV file?  Do NOT use EXCEL to look at CSV files because it will corrupt the values.

 

To share an example of what was created copy the first few lines of text from the CSV file and past into the forum using the pop-up window that appears when you use the Insert Code icon on the menu bar.  (The one that looks like {i} ).

 

Why do you care if the CSV file has quotes around some of the values?  Quotes around values in a CSV should be ignored by the reader since they are just there in case the value contains the delimiter.

BruceTao
Fluorite | Level 6

Hi Tom,

Yes, I will use the Insert Code icon the next time. I just used Excel so I could show you side by side the output from EG compared to the output from Viya. It was simply show the quotes around the labels as opposed to no quotes around the labels. 

 

This file is then moved to Google's Datalab where we will be using a Python script to perform a Random Forest method. You might be right that the quotes will not make any difference but since we are converting from EG to Viya, I would prefer that the output is exactly the same. The extra fields which you can also see in my Excel example, will certainly impact the Random Forest method in Datalab.

 

Thanks for the quick response. 

 

If you want me to resubmit the csv files, I can. However, I think just see the examples I provided in the Excel sheet would be all you need.

 

Thanks for the quick response.

 

Bruce

ballardw
Super User

@BruceTao wrote:

Hi Tom,

Yes, I will use the Insert Code icon the next time. I just used Excel so I could show you side by side the output from EG compared to the output from Viya. It was simply show the quotes around the labels as opposed to no quotes around the labels. 

 

This file is then moved to Google's Datalab where we will be using a Python script to perform a Random Forest method. You might be right that the quotes will not make any difference but since we are converting from EG to Viya, I would prefer that the output is exactly the same. The extra fields which you can also see in my Excel example, will certainly impact the Random Forest method in Datalab.

 

Thanks for the quick response. 

 

If you want me to resubmit the csv files, I can. However, I think just see the examples I provided in the Excel sheet would be all you need.

 

Thanks for the quick response.

 

Bruce


Removing the LABEL option will remove the quotes on the column headings but not use variable labels as headings, just the variable name.

 

How can we tell what is "extra"???

 

You can DROP unwanted variables on the proc export once they are identified

PROC EXPORT 
DATA=Export.tdsr_apr2019_out  (drop = variable othervariable)
DBMS=csv 
LABEL 
OUTFILE='/sasshare/prd/AUDIT/BlackMESA/Export/tdsr_apr2018_export.csv'
REPLACE;

or make sure that the step that creates the output data set does similar.

Tom
Super User Tom
Super User

I don't know why it is adding quotes. It does not do that when I try it in normal SAS 9.4M5 release.

The unneeded quotes were added by the LABEL option.

As to the variables it is just outputting the variables in your dataset. If you want different variables then change the dataset before creating the CSV file from it.

 

filename csv temp;
proc export data=sashelp.class(obs=3) file=csv dbms=csv;
  delimiter=',';
run;
357   data _null_;
358    infile csv;
359    input ;
360    list;
361   run;

NOTE: The infile CSV is:
      Filename=xxxx,
      RECFM=V,LRECL=32767,File Size (bytes)=92,
      Last Modified=13May2019:19:39:29,
      Create Time=13May2019:19:39:29

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+--
1         Name,Sex,Age,Height,Weight 26
2         Alfred,M,14,69,112.5 20
3         Alice,F,13,56.5,84 18
4         Barbara,F,13,65.3,98 20
NOTE: 4 records were read from the infile CSV.
      The minimum record length was 18.
      The maximum record length was 26.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

 

But if you generate the CSV file yourself then you can use the labels as the column headers without getting unneeded quotes.

proc transpose data=sashelp.class(obs=0) out=names ;
  var _all_;
  label name='Name Label';
run;
data _null_;
  file csv dsd ;
  length _name_ $32 _label_ $256;
  set names end=eof;
  _label_=coalescec(_label_,_name_);
  put _label_ @;
  if eof then put;
run;
data _null_;
  file csv dsd mod ;
  set sashelp.class(obs=3);
  put (_all_) (+0);
run;
617   data _null_;
618    infile csv;
619    input ;
620    put _infile_;
621   run;

NOTE: The infile CSV is:
      Filename=XXX,
      RECFM=V,LRECL=32767,File Size (bytes)=98,
      Last Modified=13May2019:19:50:38,
      Create Time=13May2019:19:45:44

Name Label,Sex,Age,Height,Weight
Alfred,M,14,69,112.5
Alice,F,13,56.5,84
Barbara,F,13,65.3,98
NOTE: 4 records were read from the infile CSV.
      The minimum record length was 18.
      The maximum record length was 32.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

 

Reeza
Super User
It's a CSV standard to include quotes around column headers and any text field since it can contain the delimiter which can mess up your data.
BruceTao
Fluorite | Level 6
1	24531336	9	19.51	0	232	-7.74	11000	598	0	1.7088888889	29852.08	5.266579974	21437.428571	0	1	0
2	24523998	8	64.05	0	490	1.44	15000	581	1	4.9344444444	78311.82	1.6212564738	61093.046667	0	4	21000
3	24502717	7	18.04	1	458	3.34	25200	536	0	16.010277778	1339.03	0.4372191474	22985.112	0	7	22200
4	24513086	7	26.93	0	510	-1.79	18500	607	1	42.6675	42182.91	0.1640592957	19585.5975	0	9	12500
5	24482182	6	61.07	0	309	-0.82	20100	605	1	30.569444444	92844.73	0.1962744207	36606.376	1	3	24900
6	24493814	6	47.09	0	354	6.17	10000	671	1	11.552777778	2134.07	0.5193556143	1767.0375	1	1	0
7	24499000	6	95.56	0	297	-7.85	10000	600	0	1.5391666667	102474.08	3.8982133189	51207.64	0	4	15400
8	24520157	6	27.01	0	246	14.99	50000	696	1	5.1455555556	181380	1.1660548478	118237.55	0	2	40000
9	24444073	5	35.14	1	664	9.34	10000	565	10	8.8069444444	1571	0.5677337959	764.6	1	1	0
10	24483459	5	29.1	1	321	12.36	13200	454	1	8.2622222222	27291.71	0.6051640667	9372.17	0	2	2200
11	24496269	5	36.91	0	264	0.47	20000	576	2	6.7325	47604.59	0.7426661716	30065.2875	0	2	3000
12	24498493	5	76.15	1	561	2.73	24000	597	10	23.333888889	105066	0.2142806124	48246.575	1	1	0
13	24500664	5	11.64	0	255	-5.88	16000	695	1	17.040833333	87575.77	0.2934128808	36505.154	0	3	4000
14	24500680	5	14.11	1	193	1.42	27000	598	2	7.1255555556	24528.06	0.7016996725	20771.474	0	1	0
15	24516016	5	36.08	1	252	17.32	50000	749	1	3.2061111111	3304.43	1.5595217467	1568.412	0	1	0
16	24519702	5	28.7	0	279	3.56	12500	533	1	6.2502777778	25052.14	0.799964446	10758.505	1	3	2500
17	24532338	5	9.22	0	139	4.09	0	0	2	6.6180555556	36227.73	0.7555089192	46284.67	0	1	0
18	24474540	4	22.64	0	222	-3.1	10000	554	1	10.9925	50200	0.3638844667	37441.74	0	1	0
19	24474656	4	4.76	0	259	7.72	15571.5	586	1	1.9991666667	51065.5	2.0008336807	31533.1	0	2	10571.5
20	24476026	4	74.76	0	875	0.3	40000	696	8	22.5425	71550	0.1774426084	31620	0	1	0
21	24485342	4	44.28	0	892	-0.91	41500	582	15	32.836944444	22324	0.1218140137	33109.2125	1	8	5000
22	24497666	4	44.17	1	370	7.2	0	0	1	14.004722222	2600	0.2856179463	1762.288	1	4	17000
23	24497773	4	1219850	0	585	-85046	20000	799	4	26.667222222	64184	0.1499968751	39510.6	1	1	0
24	24498285	4	12.48	0	326	7.19	0	0	0	3.3575	223900	1.191362621	166639.8	0	3	5000
25	24498995	4	31.64	0	357	5.19	25000	713	3	9.0416666667	48305.65	0.4423963134	14664.362	0	1	0
26	24503757	4	42.86	0	215	2.61	25000	583	1	6.8069444444	65000	0.5876351765	63542.575	0	1	0
27	24510003	4	27.36	0	462	4.05	15000	568	2	30.493888889	4009.8	0.1311738235	4137.042	0	4	18000
28	24513481	4	714.86	0	482	-5.27	40000	615	0	13.561111111	110000	0.2949610815	65305.4	0	2	10000
29	24516047	4	178.11	1	281	2.81	50000	611	1	5.2519444444	11764.48	0.7616226794	16915	0	2	40000
30	24516727	4	21.52	1	221	3.51	24500	565	1	7.0613888889	1343.74	0.5664608001	2175	0	4	14000
31	24519028	4	9.87	1	312	0.36	18800	508	1	5.9108333333	2111.2	0.6767235302	702.24	0	3	200
32	24521691	4	0	0	213	3.31	36300	793	1	5.4891666667	0	0.7287080613	68883.28	0	2	26300
33	24521898	4	60.51	0	736	2.05	37000	660	7	18.438888889	147090.43	0.2169328111	100621.09667	1	4	22200
34	24524744	4	17.95	1	319	9.8	0	0	4	14.440277778	20451.5	0.2770029816	4506.64	0	9	5000
35	24526432	4	460.4	0	489	-15.43	18000	726	6	10.488888889	86607.12	0.3813559322	35772.014	1	4	10000
36	24532756	4	23.21	1	319	7.37	11000	570	2	3.4638888889	24452.41	1.1547714515	37528.926	0	2	4000
37	24414119	3	19.71	0	822	0.59	20000	579	24	11.856111111	37488.99	0.2530340659	48203.123333	0	2	10000
38	24433820	3	99.63	1	286	0.54	3000	492	0	14.807777778	1750	0.2025962332	390.3625	0	1	0
39	24455733	3	8.32	1	473	6.66	47000	486	7	6.5441666667	66879.36	0.4584235324	33877.18	1	6	24900
40	24481163	3	14.42	1	354	0.54	22787	546	2	4.9461111111	8824.98	0.6065371223	13814.7025	0	9	24000
41	24482288	3	56.12	1	355	2.67	19000	593	8	1.8336111111	47000	1.63611574	12794.5	1	1	0
42	24490817	3	547.73	0	363	-0.31	81000	549	2	9.8933333333	10214.1	0.3032345013	4804.525	0	2	250
43	24490835	3	8.34	0	295	18.82	41000	766	3	13.549444444	146401.67	0.221411292	100907.22333	1	5	24000
44	24494788	3	43.77	0	267	6.73	25000	537	0	6.3202777778	38980.83	0.4746626818	26428.86	0	2	5000
45	24494910	3	38.41	0	242	-9.16	5000	560	1	13.808611111	4748.33	0.2172557382	3652.3575	0	1	0
46	24495088	3	7.88	0	264	-8.74	19000	541	2	14.715555556	42156.4	0.2038659015	46414.45	0	2	6000
47	24499919	3	105413.86	1	181	3.19	26500	691	1	12.680833333	27761.56	0.236577512	32597.266667	1	2	8000
48	24500635	3	35.24	1	495	21.65	15000	535	8	21.205555556	3400	0.1414723605	2234.7025	1	3	5800
49	24502172	3	37.65	0	302	4.87	0	0	1	13.623888889	720000	0.2202014435	512000	1	3	10000
50	24503059	3	2.27	0	217	20.95	18000	733	1	17.160277778	8221.5	0.1748223449	62654.786667	1	2	8000
51	24503169	3	28.73	0	374	8.52	7500	749	7	5.6988888889	0	0.5264184051	3058.31	0	1	0
52	24503186	3	2.44	0	202	3.47	21000	624	0	2.2805555556	636.73	1.3154689403	24606.99	0	7	18000
53	24504554	3	1251.76	0	259	-3.87	15000	563	1	18.496666667	100831.23	0.1621913858	75492.6475	0	1	0
54	24505284	3	28.76	1	190	2.89	30000	546	2	3.5502777778	88303	0.8450043033	23487.9	0	2	24000
55	24505521	3	32.33	1	516	16.66	50000	715	6	25.121388889	65973.41	0.1194201488	45824.3525	1	3	15000
56	24506655	3	11.84	1	154	1.43	30000	669	2	8.1608333333	25494.71	0.367609517	58498.57	0	1	0
57	24507274	3	3.59	1	180	1	28500	489	0	2.8616666667	11440	1.0483401281	37576.98	0	2	0
58	24508251	3	29.98	1	182	8.16	35000	634	1	0.5597222222	234000	5.3598014888	62738.97	0	1	0
59	24510242	3	10.15	0	383	34.13	10500	639	5	6.2847222222	47745.47	0.4773480663	36316.235	0	4	19500
60	24510802	3	7.39	1	318	0.35	10000	0	2	6.5769444444	3225.25	0.4561388689	2908.4166667	0	5	5000
61	24511192	3	34.02	0	239	-2.72	32670	578	2	6.1205555556	0	0.4901515839	112239.02	0	2	30670
62	24511223	3	7.39	0	269	14.89	12000	726	2	1.15	0	2.6086956522	74128.78	1	1	0
63	24511634	3	16.12	0	218	-1.9	30000	592	1	14.154722222	1200	0.2119434033	3250	0	1	0
64	24511647	3	6.21	0	245	16.84	27380	605	2	21.475833333	24515.32	0.1396919018	83465.89	0	3	15000
65	24512874	3	22.65	1	323	11.3	0	0	5	5.7297222222	76936.9	0.5235855917	59312.3	1	1	0
66	24513530	3	25.19	1	258	4.04	16000	563	1	12.536666667	1036	0.239298059	22025.666667	0	1	0
67	24514171	3	4.52	0	171	9.15	5000	578	1	5.7663888889	43662.21	0.5202562744	12194.105	0	1	0
68	24516324	3	16.44	1	211	0.81	15000	548	1	8.6130555556	82864	0.3483084465	21299.3725	0	1	0
69	24516965	3	6.24	0	304	0.5	5000	713	4	4.8555555556	806	0.6178489703	2096.645	0	1	0
70	24517377	3	8.53	0	195	9.47	12000	619	0	1.8202777778	61058.96	1.6481001068	49953.596667	0	6	19600
71	24517512	3	89.11	1	169	5.75	33500	595	1	6.5947222222	85022.91	0.4549092288	43443.945	0	1	0
72	24519711	3	11.74	1	256	2.74	23000	568	0	11.716666667	1885.96	0.2560455192	1402.8266667	0	7	20000
73	24521403	3	14.71	1	267	5.92	20000	643	2	3.9136111111	1800	0.7665554688	1517.285	1	3	5000
74	24528610	3	140.17	0	281	26.95	7000	503	0	8.4744444444	18673	0.3540055068	9624.5	0	1	0
75	24530694	3	63.92	1	276	13.78	10000	619	1	15.498888889	73200	0.1935622625	66600	1	1	0
76	24532659	3	11.74	1	250	7.4	12000	559	1	9.2275	24183.83	0.3251151449	6447.2075	0	6	3500
77	24533484	3	35.04	1	498	7.82	7000	620	11	1.7861111111	206062.5	1.6796267496	94015.625	1	1	0
78	24426530	2	7.39	0	264	25.38	40000	691	0	11.708055556	39450.9	0.1708225581	65225.45	0	2	10000
79	24457963	2	16.66	0	184	20.94	22500	635	1	2.6930555556	1630.17	0.742650851	18466.296667	0	2	27500
80	24475209	2	19.21	0	374	3.49	43000	587	8	4.4105555556	0	0.4534576143	21618.81	1	4	7000
81	24476424	2	16.03	0	214	20.46	20000	462	0	5.8180555556	328.32	0.34375746	2664.16	1	1	0
82	24481210	2	7.07	0	262	27.86	40000	602	1	1.3430555556	170000	1.4891416753	170000	0	1	0
83	24485812	2	101.29	0	206	-0.72	30000	0	1	3.6844444444	126005.75	0.5428226779	42751.916667	0	2	10000
84	24486138	2	470.76	1	256	42	4000	620	0	23.198611111	60000	0.0862120577	30005	0	4	6000
85	24489147	2	12.49	1	441	0.16	39000	624	2	25.712222222	160	0.0777840197	43805	0	5	16800
86	24491107	2	7.17	1	256	3.1	20000	590	1	5.9363888889	1100	0.3369051518	34811.86	0	4	10000
87	24492465	2	33.32	0	363	19.02	20000	793	4	5.9380555556	82188.97	0.3368105908	58155.063333	1	2	5000
88	24493822	2	4.29	0	274	-6.1	20000	0	3	10.595	5000	0.1887682869	28333.333333	0	6	20000
89	24493888	2	2	0	166	10.97	35000	520	1	7.0352777778	1172.11	0.2842815967	43264.795	0	2	5000
90	24494109	2	2.34	0	166	29.86	25000	606	1	3.0158333333	1018.92	0.6631666206	5733.98	1	1	0
91	24496291	2	53.27	0	517	-11.66	0	0	6	4.0897222222	2722.88	0.4890307682	19540.96	0	9	33500
92	24496758	2	14.2	0	211	-7.53	6000	646	1	1.4188888889	1000	1.4095536413	38000	0	2	1000
93	24496779	2	108.14	1	509	2.03	20000	585	7	9.2905555556	111647.79	0.2152723794	69774.58	0	2	1000
94	24496786	2	6.4	0	240	12.28	10000	525	1	6.0105555556	61928	0.3327479434	63464	1	1	0
95	24497426	2	1.78	0	192	6.7	18000	506	1	4.3216666667	1116.5	0.4627844196	61108.25	0	2	2000
96	24497460	2	17.58	0	206	17.34	50000	569	1	4.0363888889	79000	0.4954923956	94500	0	1	0
97	24497667	2	19.07	0	226	19.7	20000	581	1	6.1944444444	44999	0.3228699552	61666.666667	0	1	0
98	24497874	2	29.02	1	457	11.34	20000	651	9	16.918888889	2738.37	0.1182110724	2778.74	1	2	5000
99	24498813	2	30	0	215	7.32	10000	527	1	12.115833333	18837.31	0.1650732513	18837.31	0	5	8500
100	24499494	2	64.17	1	1032	1.69	35000	568	7	22.2575	4335.48	0.0898573515	2848.6075	1	4	30000


BruceTao
Fluorite | Level 6

Hi,

I tried removing the LABEL parameter from the export proc without any success. I have included the first 100 records of the input file along with the full output file. You labels 16 labels associated with the input file:

 

ObjValue   num_inc_change  TDSR_Distance  drop_lim   app_size   limit_delta  loan_amt  credit_score  liab_chang  sess_time_hr

 

max_min_inc_diff   sess_chg_per_hr   avg_inc_chg  JointAcct   loan_chgs   loan_max_min_diff

BruceTao
Fluorite | Level 6

I figured this out. My bad. I had my input directory pointing to the wrong file. Thanks for your support.

sas-innovate-2024.png

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.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 8 replies
  • 7152 views
  • 1 like
  • 4 in conversation