Write and run SAS programs in your web browser

Arrays

Reply
Occasional Contributor NVN
Occasional Contributor
Posts: 14

Arrays

Please help me to find the  missing values across raw with 2D array.

 

Dataset Name : "Subset .csv ";  Missing values:" NA"

 

       i_Day5   Day6           Day7         City1           City2       City3

1      Fridat    NA               NA            NA               Delhi        Mumbai

2      NA         NA               NA            NA               NA           NA

3      Friday   NA                NA           NA               NA            NA

4      Friday   Saturday      NA            Bangalore   NA           NA

5      NA         NA               NA            NA               Delhi       NA

6      Friday    Saturday     Sunday    BAngalore   NA           NA

7      NA          NA              NA            NA               Delhi       NA

8      NA          NA              NA            NA               Delhi       NA

9      NA          NA              NA            NA               NA           NA

10    Friday    Saturday     NA            NA               NA          NA

 

 

The code that am stuck with is:

 

Proc import datafile="P\A\T\H.csv"

dbms=csv  out=Subset;

run;

data subset;

set subset;

array Miss{2,10}i_Day5 Day6 Day7 City1--City3;

do i=1 to 2;

do J=1 to 10;

if Miss{i,j}="NA" then /*???????????*/;

end;

end;

Proc print data=Subset;

run;

 

Plese help  me to  compleate this problem...

Super User
Posts: 7,094

Re: Arrays

You have defined an array with 20 elements for only 6 variables.

Your condition for finding the 'NA' values is correct, but you've never stated what should happen with those values, so we can't really help you here.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Occasional Contributor NVN
Occasional Contributor
Posts: 14

Re: Arrays

The output  that am looking is,  a  7th varable " No_of_Miss"  that contain the number of missing values(number of "NA") of each raws. Like...  Number of "NA" in the 1st raw  as the 1st  observation of "No_of_Miss",  number of "NA" in the 2nd raw as the second obsercation on"No_Of_Miss"....etc up  to  10th raw. please help me sir.

Super User
Posts: 18,549

Re: Arrays

This is homework so I don't usually post answers. I'll post helpful links and gladly help you debug code, but giving you the answer isn't going to help you or me in the long run. 

 

1. How do you declare an array?

2. How do you loop through an array?

3. How do you count/increment a count. 

 

Those were all covered in the link I posted AND I posted skeleton code that you haven't attempted to use so far.  I'm not really sure what else I can help you with at this point. 

Super User
Super User
Posts: 7,565

Re: Arrays

Post test data in the form of a datastep!!!

 

From what you have posted I cannot tell what you are trying to do, do you want to count the number of NA per column or per row or across the whole data?  If it is by column, then:

proc sql;
  create table WANT as
  select count(case when I_DAY5="NA" 1 else 0 end) as I_DAY5_COUNT
...
quit;

If its by row then you only need to array across the columns you have.

And if its across all data, then transpose the data you have (normalise is) so there is only one column of all the day values and then count.

 

If you provide the information needed - test data in the form of a datastep, and what the output should look like, then we can provide further code.

Super User
Posts: 18,549

Re: Arrays

Read the link I posted. 

 

Since you're new to SAS, it's most likely you're working with the basics of arrays. An Array is only a shortcut to list variables and primarily only references values in a specific row. SAS operates by processing one row of data at a time. So the 10 in your array does not reference the number of rows. I posted how to declare the array in your previous question. Also, note than an array can have only one type of variables included in the list - character or numeric. 

 

 

Ask a Question
Discussion stats
  • 5 replies
  • 146 views
  • 0 likes
  • 4 in conversation