BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
techlearner986
Calcite | Level 5

Hi Team,

I wish you had a wonderful start to the new year 2014!

I need your help in transforming a SAS table to give me a pivot type result. Basically I need to summarize the input table in the layout of output table. A snapshot of both the tables is shown below. I am able to create the required output in excel by creating a pivot table. However, have no idea abut doing this in SAS itself.

Table - Input

Month

Cat

Amount

Jan

Cat1

£12.00

Jan

Cat2

£31.00

Jan

Cat3

£42.00

Feb

Cat1

£12.00

Feb

Cat2

£52.00

Feb

Cat3

£12.00

Feb

Cat4

£52.00

Feb

Cat5

£12.00

Mar

Cat1

£10.00

Mar

Cat2

£12.00

Mar

Cat3

£2.00

Mar

Cat4

£32.00

Mar

Cat5

£12.00

Table - Output

Cat

Jan

Feb

Mar

Cat1

£12.00

£12.00

£10.00

Cat2

£31.00

£52.00

£12.00

Cat3

£42.00

£12.00

£2.00

Cat4

£0.00

£52.00

£32.00

Cat5

£0.00

£12.00

£12.00

Rgds, tech learner

1 ACCEPTED SOLUTION

Accepted Solutions
Jagadishkatam
Amethyst | Level 16

Please try

proc sort data=have;

  by cat;

run;

proc transpose data=have   out=want(drop=_name_);

  by cat;

  id month;

  var amount;

run;

data want_;

  set want;

  array cha(3) $ jan feb mar;

  do i = 1 to 3;

  if cha(i)='' then cha(i)='£0.00';

  end;

  drop i;

  run;

Thanks,

jag

Thanks,
Jag

View solution in original post

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

Please try

proc sort data=have;

  by cat;

run;

proc transpose data=have   out=want(drop=_name_);

  by cat;

  id month;

  var amount;

run;

data want_;

  set want;

  array cha(3) $ jan feb mar;

  do i = 1 to 3;

  if cha(i)='' then cha(i)='£0.00';

  end;

  drop i;

  run;

Thanks,

jag

Thanks,
Jag
techlearner986
Calcite | Level 5

thanks jag,

data want (created by the transpose procedure) does the trick for me. I don't see any difference in data want and want_, null values not converted to 0 but thats not an issue at the moment.

many thanks for your quick help!

Cheers, tech

Jagadishkatam
Amethyst | Level 16

I checked the code again and i see want_ has £0.00 replacing the missing values of want dataset.

Could you please check the output again and let me know if there is any problem in the log.

Thanks,

Jag

Thanks,
Jag

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
  • 437 views
  • 3 likes
  • 2 in conversation