Help using Base SAS procedures

How to load a column from a CSV file into a sas array?

Reply
Frequent Contributor
Posts: 92

How to load a column from a CSV file into a sas array?

The dataset is WORK.HOLIDAYS

It looks like this:

HOLIDAY

1/1/2014

31/1/2014

14/2/2014

How do I load this dataset into any array?

Super User
Posts: 5,431

Re: How to load a column from a CSV file into a sas array?

This is basic SAS programming, and you'll find your answer in the documentation or in training material.

Question is, what is the requirement for your question?

Data never sleeps
Super User
Super User
Posts: 7,060

Re: How to load a column from a CSV file into a sas array?

Despite the title on your post it looks like you already have the data in a data set.  What do you mean by wanting to create an array? If you explain the larger picture of what you are trying to do then someone might be able suggest a method.

Frequent Contributor
Posts: 92

Re: How to load a column from a CSV file into a sas array?

THanks for the help. After spending some time, this is what I ended up with and it works.

PROC SQL;

     SELECT CAT("'", PUT(HOLIDATE,DATE9.),"'D") INTO  :HOLIDAYLIST SEPARATED BY ',' FROM SMLS.HOLIDAYS

;QUIT;

DATA SMLS.CA1;

SET SMLS.CA;

     HOLIDAY = 0;

DO HOLIDATE = &HOLIDAYLIST;

IF DATEPART(LAST_UPDATE_DATE) < HOLIDATE AND DATEPART(FIRST_UPDATE_DATE) > HOLIDATE THEN HOLIDAY = HOLIDAY + 1;

END;

IF HOLIDAY >=1 THEN SLA = SLA - (24*HOLIDAY);

OUTPUT;

DROP HOLIDATE

RUN;

Frequent Contributor
Posts: 92

Re: How to load a column from a CSV file into a sas array?

Basically counting the number of public holidays between the start date and end date.

Super User
Posts: 19,822

Re: How to load a column from a CSV file into a sas array?

That isn't an array, that's a macro variable list.

Arrays in SAS operate differently than other languages, so its worth reading the documentation.

Super User
Super User
Posts: 7,060

Re: How to load a column from a CSV file into a sas array?

No need for macro variables to do that logic.  You can read directly from the source table by using POINT= option on SET statement.

DATA SMLS.CA1;

  SET SMLS.CA;

  HOLIDAY = 0;

  DO p=1 to nobs ;

    SET SMLS.HOLIDAYS(keep=HOLIDATE) point=p nobs=nobs ;

    IF DATEPART(LAST_UPDATE_DATE) < HOLIDATE AND DATEPART(FIRST_UPDATE_DATE) > HOLIDATE

       THEN HOLIDAY = HOLIDAY + 1

    ;

  END;

  IF HOLIDAY >=1 THEN SLA = SLA - (24*HOLIDAY);

  DROP HOLIDATE

RUN;

Ask a Question
Discussion stats
  • 6 replies
  • 545 views
  • 4 likes
  • 4 in conversation