BookmarkSubscribeRSS Feed
Dennis64
Calcite | Level 5

螢幕截圖 2021-10-22 下午5.49.52.png

C23005A6,3,15,,39

146DX2356,4,11,,,5

B36AA323,3,10,15,20

F123G246H1,1,

 

 

3 REPLIES 3
PeterClemmensen
Tourmaline | Level 20

What is the logic here? And where does F123G246H1 come from?

Kurt_Bremser
Super User

Please do NOT present example data in pictures. Post a data step that creates the dataset from DATALINES, and post it in a code box (see your welcome mail). Otherwise a lot of time has to be wasted by the people trying to help you by setting up data for testing.

 

Please describe the logic for calculating and placing those numbers.

Patrick
Opal | Level 21

Providing the data in a friendlier form and a bit more description of the desired outcome would reduce guesswork and increase motivation to post an answer to your question.

Is below what you're after?

data have;
  infile datalines truncover dsd dlm=',';
  input customer_id :$20. var $ (unit1-unit4) (:best32.);
  datalines;
C23005A6,3,15,,39
146DX2356,4,11,,,5
B36AA323,3,10,15,20
F123G246H1,1,
;

data want;
  set have;
  array _units {*} unit:;
  do i=1 to dim(_units);
    if not missing(_units[i]) then 
      do;
        units_purchased=_units[i];
        output;
      end;
  end;
  keep customer_id units_purchased;
run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 826 views
  • 0 likes
  • 4 in conversation