BookmarkSubscribeRSS Feed
allurai0412
Fluorite | Level 6

hi to all,

i am working with large databases ....just providing sample obs and variables....

I need 'count' variable increment as in Desired ouput....

data have;
infile datalines;
input month sales;
datalines;
1 2000
2
3 4500
4 12200
5
6
7 45000
8 87800
9 127955
;
run;


**********desired output**********

month sales count
1     2000   1
2               0
3     4500   1
4     12200  2
5               0
6               0
7     45000  1
8     87800  2
9     127955 3

Regards

ALLU

2 REPLIES 2
andreas_lds
Jade | Level 19

Use RETAIN on the variable count with 0 as initial value, reset it to 0 if sales is missing, if sales is not missing increment it by 1.

data want;

    set have;

    length count 8;

    retain count 0;

    count = ifn(missing(sales), 0, count + 1);

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
  • 746 views
  • 4 likes
  • 2 in conversation