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
Call UploadVector(xxrange, xx())
Call UploadVector(yyrange, yy())
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
SAD_wsf = solve_adjustment(xx(), yy())
Exit Function
100 SAD_wsf = ""
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;
SAD_wsf=Solve_Adjustment(Xx{i},Yy{i});
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?
Can somebody help me, please?
Thank you
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
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.
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.