BookmarkSubscribeRSS Feed
NML
Calcite | Level 5 NML
Calcite | Level 5

I have posted this previously but unfortunately my account got scrambled and I have had to start again. I need to do a domain analysis of some data.

 

Outdoor Team Non-team Leisure Domestic

    15          5           0             0            25

     60         0           25           10           0

     0           25         30            0            0

 

I need to show the proportions each of these contribute to the whole so results should look like this

Outdoor  10%

Team       25%

Non Team  45%

Leisure     15%

Domestic   5%

 

I have on previous suggestion tried proc iml

 

proc iml;

use domains;

read all var _num_ into x[c=vname];

close;

 

ratio=t(x[+,]/sum[,ncol(x)]);

print (t(vname)) ratio[f=percent8.2];

quit;

 

but I got this message in the log

 

114

115 proc iml;

NOTE: IML Ready

116 use domains;

117 read all var _num_ into x[c=vname];

118 close;

NOTE: Closing WORK.DOMAINS

119

120 ratio=t(x[+,]/sum[,ncol(x)]);

ERROR: (execution) Matrix has not been set to a value.

operation : [ at line 120 column 18

operands : sum, , _TEM1002

sum 0 row 0 col (type ?, size 0)

 

_TEM1002 1 row 1 col (numeric)

10

statement : ASSIGN at line 120 column 1

121

122 print (t(vname)) ratio[f=percent8.2];

ERROR: Matrix ratio has not been set to a value.

statement : PRINT at line 122 column 1

123 quit;

NOTE: Exiting IML.

 

I really don't understand this procedure at all so have no idea how to fix it.

 

Can anyone help?

 

Thanks.

1 REPLY 1
ballardw
Super User

You will get much better answers if you provide an actual example of data and the output for that example data.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

 

In your "result" you are showing percentages but not defining what the numerator or denominator should be, or even what the values in the input mean. Are they counts and you want a percentage of total counts across topics or what?

 

Very likely what you want to transpose the data so that you do not have separate columns for each variable but something that looks like

Domain    value

Outdoor   15

Outdoor   60

Outdoor   0

Team       5

Team       0

etc.

 

Then you may be able to get the desired percentages (depends on what the numerators and denominators are) with Proc Freq, Tabulate or Report.

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
  • 1 reply
  • 655 views
  • 0 likes
  • 2 in conversation