Write and run SAS programs in your web browser

Arrays

Reply
Occasional Contributor NVN
Occasional Contributor
Posts: 14

Arrays

Plese help me to ave solution of the following problem.

 

Write a shorter query using SAS arrays to replace '0's as missing values in “Online Orders.csv” dataset. Use asterix(*).

 

Super User
Posts: 18,549

Re: Arrays


NVN wrote:

Plese help me to ave solution of the following problem.

 

Write a shorter query using SAS arrays to replace '0's as missing values in “Online Orders.csv” dataset. Use asterix(*).

 


Sounds like homework. How about you post what you've tried and we can help with any issues you have.

Here's a tutorial that may be helpful and probably really has the answer you need:

https://stats.idre.ucla.edu/sas/seminars/sas-arrays/

 

 

Occasional Contributor NVN
Occasional Contributor
Posts: 14

Re: Arrays

Write a shorter query using SAS arrays to replace '0's as missing values in “Online Orders.csv” dataset. Use asterix(*).

 

I executed the following  code.

 

Data online;

set online;

array miss_val=_all_;

if miss_val=0 then miss_val="*";

run;

 

Am using  virtual lab facility for sas.  So  when i execute this query the Error that am seeing is "Unfortunately your server has terminated."

 

when i  use " _numeric_ "    insted of   " _all_ "  the following error is displaying.

ERROR :  Array subscript . out of range [1- 6] of dimension 1 of array miss_val at line 100 and column 4.

 

when i  use " _character_ "    insted of   " _all_ "  the following error is displaying.

ERROR :  Array subscript . out of range [1- 14] of dimension 1 of array miss_val at line 110 and column 4

 

Trusted Advisor
Posts: 1,670

Re: Arrays

Please take a look at the documentation for the ARRAY statement. At least then you will know the proper syntax for your array statement. http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000201956.htm

 

In that documentation, please see Example 5, it is similar to what you want to do.

Super User
Posts: 18,549

Re: Arrays

1. How do you declare an array - your declaration is incorrect. 

2. You're going to need to lop through the array but you have no loop 

3. The asterisks comment is in reference to declaring an array. 

 

Heres a start for you. Review the link I included above. The first example is almost exactly your question. 

Data want;

Set have;

Array nums (*) _numeric_;

*loop start goes here;

* change to 0 goes here;

*loop end goes here;

Run;
Occasional Contributor NVN
Occasional Contributor
Posts: 14

Arrays

Write a shorter query using SAS arrays to replace '0's as missing values in “Online Orders.csv” dataset. Use asterix(*).

 

I executed the following  code.

 

Data online;

set online;

array miss_val=_all_;

if miss_val=0 then miss_val="*";

run;

 

Am using  virtual lab facility for sas.  So  when i execute this query the Error that am seeing is "Unfortunately your server has terminated."

 

when i  use " _numeric_ "    insted of   " _all_ "  the following error is displaying.

ERROR :  Array subscript . out of range [1- 6] of dimension 1 of array miss_val at line 100 and column 4.

 

when i  use " _character_ "    insted of   " _all_ "  the following error is displaying.

ERROR :  Array subscript . out of range [1- 14] of dimension 1 of array miss_val at line 110 and column

Trusted Advisor
Posts: 1,670

Re: Arrays

There's no need for multiple threads on the same topic with the exact same question. Let's continue the discussion in your other thread. https://communities.sas.com/t5/SAS-Studio/Arrays/m-p/364040#M2643

Super User
Posts: 7,094

Re: Arrays

I merged the threads.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Ask a Question
Discussion stats
  • 7 replies
  • 201 views
  • 0 likes
  • 4 in conversation