BookmarkSubscribeRSS Feed
Akarsh91
Calcite | Level 5

Dear People, 

 

I would like to know how can I insert multiple blank rows into a sas table  based on a condition. I have the following: 

 

Capture1.PNG

 

I want to do the following: 

 

If the month is equal to 1 then I want to insert 11 blank rows after the row where month is equal to 1. If the month is 8 for example then I want to insert 4 blank rows after the row where month is equal to 4 and so on such that the total doesn't exceed 12 months. I am not able to figure out what code to use in order to accomplish this task. Could anyone please help me by providing a code  that could accomplish the above task? If you need more information, please ask. Would appreciate your help. I am using sas version 9.4

 

Regards 

Akarsh 

5 REPLIES 5
Shmuel
Garnet | Level 18

You can create a nwe dataset by:

data want;
 set have;
       array all_n _numeric_;
       output;
       if month < 12 then
         do i=month +1 to 12; 
              call missing(all_n:);
              month = i;  /* all missing except month ? */
              output; 
        end;
run;
Reeza
Super User

What's the logic here? Are you trying to create a continous dataset with all months for all years?

If so, search for PRELOADFMT on here and you'll find the best solutions on how to include the missing data you want.

 

FYI In the future please post your data as text, especially if you want code. I'm not typing out your data. 

 

 


@Akarsh91 wrote:

Dear People, 

 

I would like to know how can I insert multiple blank rows into a sas table  based on a condition. I have the following: 

 

Capture1.PNG

 

I want to do the following: 

 

If the month is equal to 1 then I want to insert 11 blank rows after the row where month is equal to 1. If the month is 8 for example then I want to insert 4 blank rows after the row where month is equal to 4 and so on such that the total doesn't exceed 12 months. I am not able to figure out what code to use in order to accomplish this task. Could anyone please help me by providing a code  that could accomplish the above task? If you need more information, please ask. Would appreciate your help. I am using sas version 9.4

 

Regards 

Akarsh 


 

mkeintz
PROC Star

@Reeza

 

What the OP has is apparently a list of PERMNO's (stock id's) with data for the last month the given stock is publically listed on a major american stock exchange.  The "Names Date" is the delisting date.

 

I suppose that @Akarsh91 wants to create complete calendar year history for the delisted stocks - possibly to have all stocks with the same set of records, even if some records are dummy records.   Presumarby he/she already has monthly stock data preceding the delisting events.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Akarsh91
Calcite | Level 5

@mkeintz

 

Yes. I have Permno's and the stocks are delisted on the date that is mentioned. My main goal however is to replace the returns of with corresponding size decile returns (which I have) until the end of the year. For instance, the average size decile return is 0.02. The stock gets delisted on february 1984. From march 1984 to december 1984 the stock will be assigned the return of 0.02. The stock won't be taken into consideration after 1984. To accomplish this, i thought to  put empty rows as mentioned above in my original post and then replace the returns with the corresponding size decile returns. If you think there are more better or optimal ways to accomplish this task, please help. 

 

Thanks in advance 

 

Regards 

Akarsh 

Reeza
Super User

Create the dataset with the dates and values you want and insert those (via proc append) and the sort to get your desired order. 

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
  • 5 replies
  • 2108 views
  • 0 likes
  • 4 in conversation