BookmarkSubscribeRSS Feed
turcay
Lapis Lazuli | Level 10

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

 

 

 

4 REPLIES 4
Cynthia_sas
SAS Super FREQ

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

LinusH
Tourmaline | Level 20
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
Reeza
Super User

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. 

PGStats
Opal | Level 21

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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 957 views
  • 8 likes
  • 5 in conversation