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

Hi,

 

I have a csv table, and at the end of each column, I have the total of the column that appears. I would separate the last line, and that the line is not an observation but the total.

 

.....  , ......             , ...;

02/10/2016,126,473
03/10/2016,213,648
04/10/2016,242,809
05/10/2016,235,807
06/10/2016,285,1013
07/10/2016,260,905
08/10/2016,132,400
09/10/2016,150,446
10/10/2016,256,655

11/10/2016,249,790

,611246,1864947

,611246,1864947  here in the last line, the total of column 2 and 3.

I want :                                                   ...             .........            ....        ....


sas.JPG

 

Thank you for your help.

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User

filename x temp;
data _null_;
file x;
input;
put _infile_;
datalines;
02/10/2016,126,473
03/10/2016,213,648
04/10/2016,242,809
05/10/2016,235,807
06/10/2016,285,1013
07/10/2016,260,905
08/10/2016,132,400
09/10/2016,150,446
10/10/2016,256,655
11/10/2016,249,790
,611246,1864947
;
run;



data have;
length id $ 20;
infile x dsd truncover end=last;
input date : ddmmyy10. x y;
format date ddmmyy10.;
id=put(_n_,best. -l);
if last then id='Total';
run;
proc print noobs;run;


View solution in original post

2 REPLIES 2
Shmuel
Garnet | Level 18

Pay attention that TOTAL rows are with missing date.

 

If you use PROC IMPORT then you need add a second step, otherwise you can do it in same data step

reading your csv file to sas:

 

data want; set have;

    if date = . then delete;  /* or if missing(date) then delete */

run;

Ksharp
Super User

filename x temp;
data _null_;
file x;
input;
put _infile_;
datalines;
02/10/2016,126,473
03/10/2016,213,648
04/10/2016,242,809
05/10/2016,235,807
06/10/2016,285,1013
07/10/2016,260,905
08/10/2016,132,400
09/10/2016,150,446
10/10/2016,256,655
11/10/2016,249,790
,611246,1864947
;
run;



data have;
length id $ 20;
infile x dsd truncover end=last;
input date : ddmmyy10. x y;
format date ddmmyy10.;
id=put(_n_,best. -l);
if last then id='Total';
run;
proc print noobs;run;


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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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