Help using Base SAS procedures

Proc Import not successful

Accepted Solution Solved
Reply
Contributor
Posts: 21
Accepted Solution

Proc Import not successful

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
Solution
‎09-20-2013 05:14 AM
Contributor
Posts: 71

Re: Proc Import not successful

Posted in reply to sridhar78

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 .

View solution in original post


All Replies
Contributor
Posts: 71

Re: Proc Import not successful

Posted in reply to sridhar78

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

Contributor
Posts: 21

Re: Proc Import not successful

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

Solution
‎09-20-2013 05:14 AM
Contributor
Posts: 71

Re: Proc Import not successful

Posted in reply to sridhar78

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 .

Contributor
Posts: 21

Re: Proc Import not successful

Hi Venky,

Thanks for the quick suggestion.

This one works perfectly. Wow....amazing!

Really appreciate your help.

Thanks,

Sridhar

Contributor
Posts: 71

Re: Proc Import not successful

Posted in reply to sridhar78

Your Welcome.

If you want to extract time  use function

timepart();

Contributor
Posts: 70

Re: Proc Import not successful

Posted in reply to sridhar78

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

Contributor
Posts: 71

Re: Proc Import not successful

Posted in reply to yaswanthj

Yes Yashu this is one method. I guess he is looking for proc import method.

Contributor
Posts: 70

Re: Proc Import not successful

Posted in reply to sridhar78

Hi..

There is a semicolon(Smiley Wink in between the datafile and out. so that you can not generate the file to dataset. please remove semicolon(Smiley Wink 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.

Contributor
Posts: 71

Re: Proc Import not successful

Posted in reply to yaswanthj

@Yaswanth ,

Yes I didnt observed it. Yaswanth Was correct.

Contributor
Posts: 21

Re: Proc Import not successful

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.

Super User
Super User
Posts: 7,080

Re: Proc Import not successful

Posted in reply to sridhar78

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;

Contributor
Posts: 21

Re: Proc Import not successful

Thanks Tom.

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 12 replies
  • 2053 views
  • 4 likes
  • 4 in conversation