BookmarkSubscribeRSS Feed
SeekYourWay
Calcite | Level 5

Hi there,

I'm relatively new to SAS but just wondering if SAS has the ability to add record.

I have an Excel table contain lines of records. Because we need to make information complete, for each record in an Excel table, I need to add one additional line based on few logics. (I can do this manually, but it takes long to complete)

I know that an Excel macro can help me do the job if my logics are correctly built in, but in a general sense, does SAS have the ability to add record into existing record table? Not sure if I'm asking the right people.

Thanks

3 REPLIES 3
PGStats
Opal | Level 21

Yes, SAS can append records to an Excel dataset. There are at least two methods. Try the following (after adjusting the file path to your environment) :

libname xl excel "&sasForum.\datasets\addRecord.xlsx" scan_text=no;

data xl.one;
do x = 1 to 10;
output;
end;
run;

data two;
do x = 11 to 20;
output;
end;
run;

proc append base=xl.one data=two; run;

data three;
do x = 21 to 30;
output;
end;
run;

proc sql;
insert into xl.one select * from three;
quit;

libname xl clear;

PG

PG
SeekYourWay
Calcite | Level 5

Hi,

Thanks for your response.

If you have a moment to spare, my problem is described in the attached file.

This table is the initial record table into which one additional record needs to be added.

Record_IDAssessment_Typeadmission_dateStart_DateEnd_DateBreak_down_Necessarydays_Counted
234/11/20104/14/20104/16/2010n2
244/11/20104/16/20106/15/2010y60

the following table shows the added record

Record_IDAssessment_Typeadmission_DateStart_DateEnd_DateBreak_down_Necessarydays_Counted
234/11/20104/14/20104/16/2010n2
2added4/11/20104/16/20106/15/2010added60
244/11/20106/15/20106/15/2010n0

So, the logic is....whenever the break down necessary column shows a y, then we need to add a row ABOVE. The first row in the 2nd table remains the same. On the added line as you can see, the start_date becomes the end_date of the previous line, and its end_date is whenever the original end_date was. On the 3rd line, the start_date and end_date is the same  in this case. All three lines will have the same admission_date assigned. We get 60 for the days_counted because it's just the subtraction of start_date from end_date.

I know it may seem redundant the way that record needs to be inserted, but it will satisfy our reporting standard.

Anyone able to assist? Can this be done in SAS platform?

Thank you

richard_a
Calcite | Level 5

data new;

set orig;

if time_to_add = 1 then output new;

run;

data combined;

set orig new;

run;


Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 3337 views
  • 3 likes
  • 3 in conversation