- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
data ds;
set sashelp.class;
array new1(*) $ Name ;
array new2(*) $ Sex;
do i =1 to dim(new1);
if new1= i then uppcase(new1(i));
if new2=i then lowcase(new2(i));
end;
proc print;
run;
Here i want get Name in caps and sex in small case
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Why do you think you need an array?
data ds;
set sashelp.class;
name=upcase(name);
sex=lowcase(sex);
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here is an array based method to do the same, so you can see how to define and use an array.
data ds;
set sashelp.class;
array x name sex;
do index=1 to 2;
if index=1 then x[index]=upcase(x[index]);
else if index=2 then x[index]=lowcase(x[index]);
end;
drop index;
run;
(Note that in this case it is silly to use an array, but if your real case had dozens or hundreds of variables you wanted to process an array would make sense)
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@BrahmanandaRao wrote:
i want to get thru arrays so I am trying
One thing to learn about ARRAYs is when to use ARRAYs and when to not use ARRAYs. This is a case where you should not be using ARRAYs, and that's the lesson you need to learn.
You use ARRAYs when there are many columns and you want to execute the same code on each column. Here are several examples of actually using ARRAYs, please take a look.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Good idea to write test programs and inspect the results. Here's a variation on your program that might speed up the learning process:
data ds;
set sashelp.class;
array new (*) $ Name sex;
do i =1 to dim(new);
put 'Before: ' _all_;
new{i} = upcase(new{i});
put 'Middle: ' _all_;
new{i} = lowcase(new{i});
put 'After: ' _all_;
end;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Arrays in SAS are used as variable shortcut references and you typically operate on the same row. So if you want to do something to 30 different variables in the same observations then use an array. If you want to do something to every value in a column then you WOULD NOT use an array in that case.
There are cases where you would use an array to work on values between rows but given your questions this is beyond anything you're doing at this point.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/