- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello Everyone,
I tried to import a CSV file in SAS using Proc Import and was unsuccessful. The code is given below.
proc import datafile="E:\Sridhar\Analytics\SAS Course Material\case study\computer_peripherels\comp.csv";
Out=lib1.comp dbms=csv;
run;
After several attempts I imported through the wizard so that I can move and and complete my work. Let me know
what are the errors or issues in the code above. The file patch is correct and the CSV file has "comma" as delimiter.
Two quick questions
1) Is there any difference between doing a Proc Import through Code vs. doing it via the File>Import data wizard or alternatively copying the file on to the server.
2) Can you guide me on the graphical/menu options for importing, exporting, copying files ? This will help me save time on coding for these and spend more time on
the analysis part of the code.
Thanks,
Sridhar
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Try this
Data lib1.comp_new;
Set lib1.comp;
Inv_date=datepart(invoice_date);
Format inv_date date9. ;
Run;
Proc print data=lib1.comp_new;
Run;
Regards,
venky
Note: If your issue is resolved please close .
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi sridhar,,
1) There is no difference both are same. There are two different ways to import file into SAS. If using file>import method u need to have some setup to install to import Excel files into sas. Where as if you are using IMPORT procedure there is no need for that because you are saying to tool that you what to import excel file.
2) You can fine the IMPORT and EXPORT in file menu. You can find in base sas(I'm using base sas ). As per my knowledge if you are looking for GUI export one is as I mentioned above and other option you can do is if u want to data in excel file go the data set>right click > there u can find excel.
Please go through below links it may help you.
http://www.ats.ucla.edu/stat/sas/faq/rwxls8.htm
http://rfd.uoregon.edu/files/rfd/StatisticalResources/dt06_import.txt
SAS/ACCESS(R) 9.2 Interface to PC Files: Reference, Second Edition
Can I know which sas version you are using.
Regards,
venky
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Venky,
Thanks for your prompt response and for clarifying my questions.
I'm using SAS Enterprise Guide 4.3.
I also have a query reg. copying/extracting date from one column to another. Please answer this if time permits - it will be very helpful.
I was trying to extract Invoice date info. to another column (i.e from invoice_date col to inv-date). The code is below.
data lib1.comp_new;
set lib1.comp;
inv_date=input(invoice_date,datetime22.);
format inv_date datetime22.;
run;
The reason I'm doing this is Invoice_Date has date and time info, whereas I need only the date, so I'm copying the date parameters to Inv_Date. Any suggestions?
Thanks once again.
Regards,
Sridhar
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Try this
Data lib1.comp_new;
Set lib1.comp;
Inv_date=datepart(invoice_date);
Format inv_date date9. ;
Run;
Proc print data=lib1.comp_new;
Run;
Regards,
venky
Note: If your issue is resolved please close .
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Venky,
Thanks for the quick suggestion.
This one works perfectly. Wow....amazing!
Really appreciate your help.
Thanks,
Sridhar
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Your Welcome.
If you want to extract time use function
timepart();
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Srider,
You can import the CSV file using infile statement. this should be easy way to import the file..to sas..
data want;
infile "E:\Sridhar\Analytics\SAS Course Material\case study\computer_peripherels\comp.csv";
/*input var */
run;
Thanks,
Yashu
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Yes Yashu this is one method. I guess he is looking for proc import method.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi..
There is a semicolon(;) in between the datafile and out. so that you can not generate the file to dataset. please remove semicolon(;) and run. you will get the results with out any error..
proc import datafile="E:\Sridhar\Analytics\SAS Course Material\case study\computer_peripherels\comp.csv"
Out=lib1.comp dbms=csv;
run;
Thanks,
Yaswanth J.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Yaswanth ,
Yes I didnt observed it. Yaswanth Was correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Yashwanth.
The semicolon was placed wrongly. Without it the proc import would have worked. Good catch.
I'll try the 'infile' option next time.
Thanks for the valuable suggestions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here is a style tip to reduce the risk of this type of mistake. When writing a long SAS statement that takes multiple lines place the semicolon on a new line like you would with a DO/END block. Indent the middle lines of the long statement.
%let filen=E:\Sridhar\Analytics\SAS Course Material\case study\computer_peripherels\comp.csv ;
proc import datafile="&filen"
out=lib1.comp
dbms=csv
;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Tom.