I cant able to use "Dim" code while practicing arrays in university edition. Kindly help.
data Sales;
input Product $ Cprice Sprice Profit;
cards;
Chairs 200 400 .
Tables 125 . 121
ladder . 596 125
Desk 148 265 .
;
run;
proc print data=sales;
run;
data test2;
set Sales;
array abc (*) _numeric_;
do i=1 to dim(sales)
if abc {i}=. then abc{i}=0;
end;
run;
proc print data=test2;
ERROR:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73
74 data test2;
75 set Sales;
76 array abc (*) _numeric_;
77 do i=1 to dim(sales)
78 if abc {i}=. then abc{i}=0;
__
79
ERROR: The DIM, LBOUND, and HBOUND functions require an array name for the first argument.
ERROR 79-322: Expecting a ;.
79 end;
80 run;
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TEST2 may be incomplete. When this step was stopped there were 0 observations and 6 variables.
WARNING: Data set WORK.TEST2 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.01 seconds
81 proc print data=test2
82
83 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
_______
22
76
ERROR 22-322: Syntax error, expecting one of the following: ;, (, BLANKLINE, CONTENTS, DATA, DOUBLE, GRANDTOTAL_LABEL,
GRANDTOT_LABEL, GRAND_LABEL, GTOTAL_LABEL, GTOT_LABEL, HEADING, LABEL, N, NOOBS, NOSUMLABEL, OBS, ROUND, ROWS, SPLIT,
STYLE, SUMLABEL, UNIFORM, WIDTH.
ERROR 76-322: Syntax error, statement will be ignored.
84 ODS HTML CLOSE;
85 &GRAPHTERM; ;*';*";*/;RUN;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
85 ! QUIT;
86 QUIT;RUN;
87 ODS HTML5 (ID=WEB) CLOSE;
88
89 ODS RTF (ID=WEB) CLOSE;
90 ODS PDF (ID=WEB) CLOSE;
NOTE: ODS PDF(WEB) printed no output.
(This sometimes results from failing to place a RUN statement before the ODS PDF(WEB) CLOSE statement.)
91 FILENAME _GSFNAME;
NOTE: Fileref _GSFNAME has been deassigned.
92 DATA _NULL_;
93 RUN;
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
94 OPTIONS VALIDMEMNAME=COMPAT;
95 OPTIONS NOTES STIMER SOURCE SYNTAXCHECK;
96
data test2; set Sales; array abc (*) _numeric_; do i=1 to dim(sales) if abc {i}=. then abc{i}=0; end; run;
DIM takes an ARRAY name as the argument of the function. SALES as far as I can see is a data set name, not an array. The only array possible in this step to use with the DIM function is ABC.
You have other syntax issues such as missing ; before the options statement on line 83
Hi,
what code should I use other than DIM? As it is not working in SAS UE.
Nothing to do with arrays. Put a semicolon at the end of the DO statement:
do i=1 to dim(abc); /* <=== HERE */
data test2; set Sales; array abc (*) _numeric_; do i=1 to dim(abc); if abc{i}=. then abc{i}=0; end; run;
Try this code. Two modifications are required.
1. A Semi colon was missing at the end of the do statement.
2. Array name should be used inside dim
data Sales;
input Product $ Cprice Sprice Profit;
cards;
Chairs 200 400 .
Tables 125 . 121
ladder . 596 125
Desk 148 265 .
;
run;
proc print data=sales;
run;
data test2;
set Sales;
array abc (*) _numeric_;
do i=1 to dim(abc);
if abc {i}=. then abc{i}=0;
end;
run;
Hi,
what code should I use other than DIM? As it is not working in SAS UE.
Whenever you say "it is not working," please show us the output and explain what you think the output should have been.
Your code works fine if the goal is to replace missing values by 0. The output should be
proc print data=test2;
run;
Obs | Product | Cprice | Sprice | Profit | i |
---|---|---|---|---|---|
1 | Chairs | 200 | 400 | 0 | 4 |
2 | Tables | 125 | 0 | 121 | 4 |
3 | ladder | 0 | 596 | 125 | 4 |
4 | Desk | 148 | 265 | 0 | 4 |
Yes Rick, I need 0 in my results, But I still get . in my result. Apologies for wage posts.
Log:
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 data Sales;
74 input Product $ Cprice Sprice Profit;
75 cards;
NOTE: The data set WORK.SALES has 4 observations and 4 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds
80 ;
81 run;
82 proc print data=sales;
83 run;
NOTE: There were 4 observations read from the data set WORK.SALES.
NOTE: PROCEDURE PRINT used (Total process time):
real time 0.08 seconds
cpu time 0.08 seconds
84
85 data test2;
86 set Sales;
87 array abc (*) _numeric_;
88 do i=1 to dim(abc);
89 if abc {i}=. then abc{i}=0;
90 end;
91 run;
NOTE: There were 4 observations read from the data set WORK.SALES.
NOTE: The data set WORK.TEST2 has 4 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
92
93 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
106
Result
Obs Product Cprice Sprice Profit
1 Chairs 200 400 .
2 Tables 125 . 121
3 ladder . 596 125
4 Desk 148 265 .
the only PROC PRINT in your program is of the original data (Sales). You need
proc print data=Test2; run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.