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

Thank you for taking the time to contribute the code, hashman! My larger dataset causes this error:

ERROR: Array subscript out of range 

_i_=8 z=0 pole=f1pos corpus= wrcount=. file= baby=. back=. ball=. bear=. beat=. begin=. believe=. bitch=. black=. block=. blow=.
blue=. body=. bottle=. bout=. brain=. break=. bring=. call=. care=. catch=. cause=. chance=. change=. check=. close=. cold=. come=.
cool=. crazy=. crime=. dance=. dark=. dead=. **bleep**=. doctor=. dollar=. door=. dream=. drink=. drive=. everything=. face=. fall=.
feel=. find=. fine=. fire=. first=. floor=. follow=. foot=. forget=. free=. friend=. front=. **bleep**=. full=. game=. girl=. give=.
good=. gotta=. great=. green=. ground=. grow=. guess=. hand=. happen=. happy=. hard=. hate=. head=. hear=. heart=. high=. hold=.
home=. hope=. house=. hurt=. keep=. kill=. kiss=. know=. lady=. last=. learn=. leave=. life=. light=. like=. line=. listen=.
little=. live=. long=. look=. lose=. love=. make=. many=. matter=. mean=. meet=. middle=. mind=. mine=. miss=. money=. more=.
morning=. mother=. motherf=. move=. much=. name=. neck=. need=. next=. night=. nobody=. nothing=. number=. only=. open=.
other=. part=. party=. peace=. people=. phone=. pill=. place=. play=. please=. problem=. pull=. radio=. rain=. read=. real=.
reason=. remember=. rest=. ride=. right=. rock=. roll=. round=. same=. search=. seem=. send=. sense=. shix=. shoot=. shot=. show=.
side=. sing=. single=. skin=. sleep=. smile=. somebody=. someone=. something=. song=. soul=. sound=. space=. speak=. spot=. stand=.
star=. start=. stay=. stick=. stop=. street=. strong=. take=. talk=. tear=. tell=. test=. thing=. think=. thought=. throw=. time=.
today=. touch=. town=. true=. turn=. understand=. voice=. wait=. walk=. wall=. wanna=. want=. watch=. whole=. wish=. woman=. word=.
work=. world=. wrong=. year=. young=. F1=. F2=. F3=. _ERROR_=1 _N_=1
 

for this line:

x[1,_i_] = input (char (pole, 2), 1.) ;

 

hashman
Ammonite | Level 13

@tonybesas:

Well, you must've realized that 7 means the number of variables in question you showed in your input sample. Obviously, now you have more. So, just to account for (almost) all eventualities, instead of:

array x [2,7] _temporary_ ; 

code:

array x [2,999999] _temporary_ ; 

 I doubt you can have more than 999999 variables in ONE, so it should cover the territory. All you risk to lose is extra 16 MB of memory. It would matter 25 years ago on the mainframe with REGION=256K. Nowadays, it's peanuts. 

 

Or just use the hash variant, as it's self-adjusting to the number of variables in ONE and records in TWO, plus it doesn't care whether the orders of the variable names in ONE and values of WORD in TWO match.

 

Kind regards

Paul D.

tonybesas
Obsidian | Level 7
Thank you, Paul, I'll try this!
tonybesas
Obsidian | Level 7

hashman kindly posted a replacement for the line:

 

 

   array x [2,7] _temporary_ ;

 

which is this:

 

   array x [2,99999] _temporary_ ;

 

this accommodates a much larger number of variables.

 

the revised code:

 

 

data want ; 
   array x [2,99999] _temporary_ ; 
   if _n_ = 1 then do _i_ = 1 by 1 until (z) ; 
       set two (keep = pole) end = z ; 
       x[1,_i_] = input (char (pole, 2), 1.) ; 
       x[2,_i_] = choosen (findc ("np", char (pole,3)), -1, 1) ; 
  end ; 
  set one ; 
  array v baby--young ; 
  array F [3] ; 
  do over v ; 
     _n_ = x[1,_i_] ; 
     f[_n_] = sum (f[_n_], v * x[2,_i_]) ; 
  end ;
run ; 

 

this worked really well!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 18 replies
  • 3934 views
  • 7 likes
  • 6 in conversation