hi, actually it would be great if I can have code for the following probem
I have a large no. of variable but I'm just presenting for few. suppose I have a file named A of the following form
s e d v1 v2 v3 v4 v5 v6
1 2 6 2 1
2 3 5 4 1 1 1
3 1 1 1 1 1
4 2 3 5 1 1 1 1
In the above data file, red colored numbers are just the serial number, and blank spaces means missing variables
Now I want to put 5 in the variables starting from s=2 and ending at e=6, e.i. starting from v2 to v6, if the variable d is greater than 1. But I want the columns s & e as the index of starting and ending of entry, I don't want the incorporation of variables directly, so that I can use this programme for a very large number of variables and cases, and for that the entry of 5 in the data file depends on the s and e variables. e.g. If s is 2 then the recoding should start from v2 and if e is 6 the recoding should end at v6. Now I want my new table looks like as follows:
s e d v1 v2 v3 v4 v5 v6
1 2 6 2 1 5 5 5 5 5
2 3 5 0 1 1 1
3 1 1 1 1 1
4 2 3 5 1 5 5 1 1 1
This means that, the previous entries in the table remains as before and just put 5 in the required fields.
It would be of great healp if you send me the code for doing this.
Use an array :
data have;
input
s e d v1 v2 v3 v4 v5 v6;
datalines;
2 6 2 1 . . . . .
3 5 0 1 1 . . . 1
. . . 1 1 1 1 . 1
2 3 5 1 . . 1 1 1
;
data want;
set have;
array _v{*} v:;
if d > 1 then
do i = max(1,s) to min(dim(_v),e);
_v{i} = 5;
end;
drop i;
run;
proc print data=want noobs; run;
awesome...thanks a lot for the code...
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.