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

HI there,

     First of all, thanks for reading this discussion.

     i have a some code written that i want to append data that extracted from a series of csv file into one dataset.

     what i have done is i "indirectly" append by temporaly store into a temp sas table then call proc append append into a detail table.

     my code written like this:

Data etllib.TEMPSDelivered_NonDeliveredFact;

      infile indir(&fname) truncover delimiter=',' FIRSTOBS=2;

      input CardCode:$15. CardName:$100. Block:$100. StreetNo:$100. Address:$100. ZipCode:$20. State:$100. Country:$100. fatherCard:$15. CardReceipt:$100. CardReceiptID:$15. Active:$1. Region:$200. Route_Code:$8.

               Branch_Code:$8. Route_Day:$8. Delivery_Date:yymmdd10. ItemCode:$20. ItemName:$100. Quantity UOM:$20. RouteFreq:$100. Route_Sequence Route_Truck:$100. DeliveredStatus:$1. Reason:$100. LogTime:time. LogDate:yymmdd10.;

      file outdir(&Read&fname);

      put _INFILE_;

run;

proc append base=etllib.Delivered_NonDeliv data=etllib.TEMPSDelivered_NonDeliveredFact;

run;

Note:- "indir(&fname)" is a file path name that refer to a csv file.

     - TEMPSDelivered_NonDeliveredFact is a temporaly table.

     - Delivered_NonDeliv is a detail table.

PS: this process is in a nested loop.

Problem: am i just can direct append on the infile statment there instead of insert into  TEMPSDelivered_NonDeliveredFact and call

                proc append to done this job?

     Please, help me..thank you everyone...

     Thank you.

Best Regards

LiangCk

1 ACCEPTED SOLUTION

Accepted Solutions
BrunoMueller
SAS Super FREQ
LiangCk
You can make use of DATA Step views, in this way there is no SAS Data set created by the DATA Step but a view.
The code for the view is executed when you access the view for instance when using Proc APPEND, see code below for a sample.
A question on the code sample you provided: is there a reason that you use infile/input as well as file/put, just curious.
Bruno
*
* create a DATA Step view
*;

data work.mycsv_Temp / VIEW=work.mycsv_Temp;
  infile mycsv dlm=";" dsd;
 
input
    name :
$16.
    sex :
$1.
    age :
8.
  ;
run;

*
* append to existing using DATA Step view
*;

proc append
 
base=work.mycsv_base
 
data=work.mycsv_Temp
;
run;

View solution in original post

4 REPLIES 4
BrunoMueller
SAS Super FREQ
LiangCk
You can make use of DATA Step views, in this way there is no SAS Data set created by the DATA Step but a view.
The code for the view is executed when you access the view for instance when using Proc APPEND, see code below for a sample.
A question on the code sample you provided: is there a reason that you use infile/input as well as file/put, just curious.
Bruno
*
* create a DATA Step view
*;

data work.mycsv_Temp / VIEW=work.mycsv_Temp;
  infile mycsv dlm=";" dsd;
 
input
    name :
$16.
    sex :
$1.
    age :
8.
  ;
run;

*
* append to existing using DATA Step view
*;

proc append
 
base=work.mycsv_base
 
data=work.mycsv_Temp
;
run;
Liangck
Calcite | Level 5

Hi bruno,

     Thanks for replying my discussion.

      First, replying your question.

     Answer is YES, you are correct. I used it for creating a duplicate csv/file from the orginal file that i read. Something like duplication of a file or back up file.

     indir() = is actualy a file directory and inside () is file name.

     

     Beside, one question for sir, you mention using view. for my understanding, view is just create a temporary table in memory is it?

     what i done is registering a "TEMP" table in a physical way.

     Which one is much more better way? interm of performance and accurate?

     Thank you and sorry for my poor english level.

Best Regards:

Liang Ck

BrunoMueller
SAS Super FREQ

Liang

When one is accessing a view (SQL or DATA Step), the data from the view is materialized and exists while reading from the view.

If you read the data from the view several times, it is usually better to make a SAS Data Set out of it.

Bruno

Liangck
Calcite | Level 5

Hi Bruno,

Thank for your advice, i think i shall used back my method because this process related to dynamically read external file.

Static is much better...

Thanks again..

Liang Ck

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!

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.

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
  • 4 replies
  • 2478 views
  • 3 likes
  • 2 in conversation