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
Why do you think you need an array?
data ds;
set sashelp.class;
name=upcase(name);
sex=lowcase(sex);
run;
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)
@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.
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;
Here's a tutorial on using Arrays in SAS
https://stats.idre.ucla.edu/sas/seminars/sas-arrays/
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.