## What is the meanning of Call&ReDim Preserve functions meaning on SAS?(VB.Net)

Super Contributor
Posts: 413

# What is the meanning of Call&ReDim Preserve functions meaning on SAS?(VB.Net)

Hello everyone,

Nowadays, I am trying to convert the code from Visual Basic to SAS. When I tried to convert these codes, I had a difficulties, I did not find some functions which are corresponding to SAS code.

Can somebody help me to convert the following code, please?

Visual Basic Code

Dim xx() As Double, yy() As Double, n As Long, i As Long, temp As Double
n = UBound(xx(), 1)
temp = 0
For i = 0 To n
If xx(i) = 0 Then Exit For
If yy(i) = 0 Then yy(i) = 0.0000000000001
temp = xx(i) + temp
Next
n = i - 1
ReDim Preserve yy(n), xx(n)

For i = 0 To n
xx(i) = xx(i) / Target / temp
yy(i) = (1 - yy(i)) / yy(i)
Next

Exit Function
End Function

SAS Code;

Data Want;
Set Have;

Array Xx{&CountX.} (&ArrayX.);
Array Yy{&CountY.} (&ArrayY.);

Call UploadVector(xxrange, xx());/*How can I conver this statement*/
Call UploadVector(yyrange, yy());/*How can I conver this statement*/

N=HBound(Xx,1);
Temp=0;

Do i=0 To N;
IF Xx{i}=0 Then Leave;
IF Yy{i}=0 Then Do;
Yy{i}=0.0000000000001;
Temp=Xx{i}+Temp;
End;
End;
/*ReDim Preserve yy(n), xx(n); How can I conver this statement */
N=i-1;

Do i=0 To N
Xx{i}=Xx{i}/Target/Temp;
Yy{i}=(1-Yy{i})/Yy{i};
End;

100 SAD_wsf = ""; /*What does it mean*/
Run;

I just don't understand the meanning of Call UploadVector and ReDim Preserve. I thought a person who has some knowledge about Visual Basic, can help me to convert this options to SAS code?

Thank you

SAS Super FREQ
Posts: 9,368

## Re: What is the meanning of Call&ReDim Preserve functions meaning on SAS?(VB.Net)

Hi:

Looking in the MSDN doc, it seems that those might have something to do with ARRAY processing in VB:

Call https://msdn.microsoft.com/en-us/library/sxz296wz.aspx
Transfers control to a Function, Sub, or dynamic-link library (DLL) procedure.

So you need to find out what the "UploadVector" function, sub or DLL does
Here's the MSDN site for the Function statement: https://msdn.microsoft.com/en-us/library/sect4ck6.aspx
Here's the MSDN site for the Sub statement: https://msdn.microsoft.com/en-us/library/dz1z94ha.aspx

ReDim Statement re-allocates storage space for an array variable
https://msdn.microsoft.com/en-us/library/w8k3cys2.aspx

Have you tried just recoding them using SAS Array processing, such as we show in the Programming 2 class? It seems, for example, that ReDim is allocating storage, which you don't need to worry about with SAS Arrays.

Here's a paper on SAS Arrays to get you started: https://support.sas.com/rnd/papers/sgf07/arrays1780.pdf

cynthia

Super User
Posts: 5,881

## Re: What is the meanning of Call&ReDim Preserve functions meaning on SAS?(VB.Net)

Vb and SAS are two quite different beasts.
Conversion of code line by line is not a good idea, handed are that you end up with quite a messy SAS application.
It's better to define the requirements, like what the old application produced with what input data. Then design and develop your SAS application based on that, not individual lines of Vb code.
Data never sleeps
Super User
Posts: 23,724

## Re: What is the meanning of Call&ReDim Preserve functions meaning on SAS?(VB.Net)

You also need to be familiar with your data structure.

If your data/array is in a row then you'll need a loop, but if your data/array is in a column then you won't need the loop because of SAS implicit loop.

I highly echo @LinusH recommendation. Determine what process is doing and replicate that. Test them against each other.

Posts: 5,529

## Re: What is the meanning of Call&ReDim Preserve functions meaning on SAS?(VB.Net)

I agree with above comments entirely.

That said,

ReDim Preserve yy(n), xx(n)

serves to redimension arrays yy and xx to size n and to keep their current values (up to size n). Array redimensioning doesn't exist is SAS datastep programming.

PG
Discussion stats
• 4 replies
• 339 views
• 8 likes
• 5 in conversation