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

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

1 ACCEPTED SOLUTION

Accepted Solutions
pallis
Fluorite | Level 6

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

12 REPLIES 12
pallis
Fluorite | Level 6

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

sridhar78
Calcite | Level 5

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

pallis
Fluorite | Level 6

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 .

sridhar78
Calcite | Level 5

Hi Venky,

Thanks for the quick suggestion.

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

Really appreciate your help.

Thanks,

Sridhar

pallis
Fluorite | Level 6

Your Welcome.

If you want to extract time  use function

timepart();

yaswanthj
Fluorite | Level 6

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

pallis
Fluorite | Level 6

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

yaswanthj
Fluorite | Level 6

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.

pallis
Fluorite | Level 6

@Yaswanth ,

Yes I didnt observed it. Yaswanth Was correct.

sridhar78
Calcite | Level 5

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.

Tom
Super User Tom
Super User

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;

sridhar78
Calcite | Level 5

Thanks Tom.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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