BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ani7
Obsidian | Level 7

I have a dataset that contains a range of IDs in numeric format that looks like this:

ID
4
98

How would I create a dataset that essentially has all values that are within 2 values of the ID in the above table? The final table should look like this

 

ID
2
3
4
5
6
96
97
98
99
100

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data want;
set have;

do i= (ID-2) to (ID+2) by 1;
      output;
end;

run;

If you need account for values less than 0 you may need to add in some more checks, but otherwise this should work.

 


@Ani7 wrote:

I have a dataset that contains a range of IDs in numeric format that looks like this:

ID
4
98

How would I create a dataset that essentially has all values that are within 2 values of the ID in the above table? The final table should look like this

 

ID
2
3
4
5
6
96
97
98
99
100

 


 

View solution in original post

2 REPLIES 2
CarmineVerrell
SAS Employee

/*Two options below..*/

 

/*First option is with Macro variables, you create two macros, start and end and assign values */

%let Start=4;
%let end=98;

Data file1(drop=i);
do i=&start to &end;
Id=i;
output;
end;
run;

 

/*Second option would be to use your datasource that has two observations in sorted order */
Data source;
ID=4;
output;
ID=98;
output;
run;

Data file2(drop=i);
set source end=eof;
retain start end;
if _n_=1 then start=id;
else end=id;
if eof then do;
do i=&start to &end;
Id=i;
output;
end;
end;
run;

Reeza
Super User
data want;
set have;

do i= (ID-2) to (ID+2) by 1;
      output;
end;

run;

If you need account for values less than 0 you may need to add in some more checks, but otherwise this should work.

 


@Ani7 wrote:

I have a dataset that contains a range of IDs in numeric format that looks like this:

ID
4
98

How would I create a dataset that essentially has all values that are within 2 values of the ID in the above table? The final table should look like this

 

ID
2
3
4
5
6
96
97
98
99
100

 


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Autotuning Deep Learning Models Using SAS

Follow along as SAS’ Robert Blanchard explains three aspects of autotuning in a deep learning context: globalized search, localized search and an in parallel method using SAS.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 1994 views
  • 1 like
  • 3 in conversation