BookmarkSubscribeRSS Feed
SBRVamsi
Fluorite | Level 6

 

 

Hi All,

 

My data looks like this

 

ID      '28-Feb-14'n  ...'28-Feb-16'n  Policy_Start

101     90.20           .....  30.89           21JAN2014

102     76.90          ....... 45.67           13MAR2015

103     66.66           ...... 67.45            20JUN2015

 

i need to add up all the columns which are less than this formula

New_Column=(sum(all_columns_which are less than policy_start+365 )<(policy_start+365))

please kindly note all the columns names are with date.

So how i refer only those columns to sum up .

 

Please revert asap.

 

Thanks,

Vamsi.

 

 

3 REPLIES 3
mkeintz
PROC Star

Question:  what about leap years?  Do you really want policy_start+365, or do you want INTNX('year',policy_start,1,'s')?  (look it up).

 

pseudo-code:

 

  •   Make a DATA step, using
    • array values {*} '28-feb-14'n -- '28-feb-16'n;
  • Loop over the values array:
    • Get the name of the variable (see VNAME function).  This yields a character value like "28-feb-14".
    • Convert that character value to a sas date value (see the INPUT function)
    • if the value is less than the target date, add the corresponing element of values to sum

 

 

    

 

--------------------------
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

--------------------------
SBRVamsi
Fluorite | Level 6
can you please write down the sample code
Reeza
Super User

Transpose your data to a long format makes this much easier. 

 

Dates shouldn't be variable names - you're storing information in your variable names. 

This is fine for reporting but not great for data analysis. 

It's harder to develop dynamic processes around variable names that constantly change and the number of variables will also change. And when adding data you have to add new columns instead of rows. 

 

Can you change your data to a long format for analysis and then transpose for reporting? 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 1235 views
  • 3 likes
  • 3 in conversation