<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How to translate a matlab code to SAS IML in SAS/IML Software and Matrix Computations</title>
    <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-translate-a-matlab-code-to-SAS-IML/m-p/59109#M367</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't say what kind of help you're looking for. For general pointers, see &lt;A href="http://blogs.sas.com/content/iml/2011/03/09/translating-a-matlab-program-into-the-sasiml-language-a-case-study/"&gt;http://blogs.sas.com/content/iml/2011/03/09/translating-a-matlab-program-into-the-sasiml-language-a-case-study/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can look up the various MATLAB functions at &lt;A href="http://www.mathworks.com/help/techdoc/"&gt;http://www.mathworks.com/help/techdoc/&lt;/A&gt; to see what they do.&amp;nbsp; I assume that you know what the code is supposed to be doing? If so, and assuming that you know SAS/IML, I suggest you try to translate as much as possible into SAS/IML and then ask specific SAS/IML questions. It looks like you'll need to use the following SAS/IML functions: J (for ones() and zeros(), RANDGEN (for rand()), LOC (for find()?), RandNormal (for mvnrnd()),...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For help with generating random uniform numbers, see &lt;A href="http://blogs.sas.com/content/iml/2011/08/24/how-to-generate-random-numbers-in-sas/"&gt;http://blogs.sas.com/content/iml/2011/08/24/how-to-generate-random-numbers-in-sas/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;For help on sampling from multivariate normal with a given covariance, see &lt;A href="http://blogs.sas.com/content/iml/2011/01/12/sampling-from-the-multivariate-normal-distribution/"&gt;http://blogs.sas.com/content/iml/2011/01/12/sampling-from-the-multivariate-normal-distribution/&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 Sep 2011 00:09:55 GMT</pubDate>
    <dc:creator>Rick_SAS</dc:creator>
    <dc:date>2011-09-01T00:09:55Z</dc:date>
    <item>
      <title>How to translate a matlab code to SAS IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-translate-a-matlab-code-to-SAS-IML/m-p/59108#M366</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hey, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a piece of matlab code to generate normally distributed cluster data. Since I don't have matlab installed in my PC, I am thinking to translate it to SAS IML. I just know a little with matlab. could anyone help with this? The matlab code is as below. Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN style="font-size: 10pt;"&gt;&lt;SPAN lang="EN"&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;%&lt;/P&gt;&lt;P&gt;rand('state',91225);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;randn('state',19481);&lt;/P&gt;&lt;P&gt;lowBound = -50;&lt;/P&gt;&lt;P&gt;highBound =50;&lt;/P&gt;&lt;P&gt;nCenters = 20;&lt;/P&gt;&lt;P&gt;nCols = 32;&lt;/P&gt;&lt;P&gt;nRows = 20000;&lt;/P&gt;&lt;P&gt;nTestRows = 0.01 * nRows;&lt;/P&gt;&lt;P&gt;nBufferPoints = 100000;&lt;/P&gt;&lt;P&gt;nExpandFactor = 10; % How much to stretch the covariance matrix&lt;/P&gt;&lt;P&gt;sTrainFile = 'outtrain.txt';&lt;/P&gt;&lt;P&gt;sTestFile = 'outtest.txt';&lt;/P&gt;&lt;P&gt;% Generate the centers according to a uniform distibution.&lt;/P&gt;&lt;P&gt;mCenters = round(lowBound + rand(nCenters,nCols)*(highBound-lowBound));&lt;/P&gt;&lt;P&gt;% Generate the variances and covariances randomly to create a matrix for&lt;/P&gt;&lt;P&gt;% each center&lt;/P&gt;&lt;P&gt;mCovariance = zeros(nCols,nCols);&lt;/P&gt;&lt;P&gt;cCovariance = cell(nCenters,1);&lt;/P&gt;&lt;P&gt;for i = 1:nCenters,&lt;/P&gt;&lt;P&gt;mRootCovariance = nExpandFactor * ...&lt;/P&gt;&lt;P&gt;rand(nCols,nCols)*(highBound-lowBound) / 50;&lt;/P&gt;&lt;P&gt;cCovariance{i} = mRootCovariance' * mRootCovariance;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;% Determine what proportion of points will come from each center, then&lt;/P&gt;&lt;P&gt;% create a cdf to use in deciding which to generate.&lt;/P&gt;&lt;P&gt;vPointFraction = rand(nCenters,1);&lt;/P&gt;&lt;P&gt;vPointFraction = vPointFraction / sum(vPointFraction);&lt;/P&gt;&lt;P&gt;vPointCdf = zeros(1,nCenters);&lt;/P&gt;&lt;P&gt;for i = 1:nCenters,&lt;/P&gt;&lt;P&gt;vPointCdf(i) = sum(vPointFraction(1:i));&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;% Create a random separating plane.&lt;/P&gt;&lt;P&gt;w = -2 + rand(nCols,1)*4;&lt;/P&gt;&lt;P&gt;gamma = lowBound / 10 + rand * (highBound-lowBound)/10;&lt;/P&gt;&lt;P&gt;% Now choose which classes to which each center belongs&lt;/P&gt;&lt;P&gt;vCenterClasses = sign(mCenters * w - gamma * ones(nCenters,1));&lt;/P&gt;&lt;P&gt;vZeroSpots = find(vCenterClasses==0);&lt;/P&gt;&lt;P&gt;vCenterClasses(vZeroSpots) = ones(length(vZeroSpots),1);&lt;/P&gt;&lt;P&gt;% Prepare output file&lt;/P&gt;&lt;P&gt;flatfile([],sTrainFile,0);&lt;/P&gt;&lt;P&gt;flatfile([],sTestFile,0);&lt;/P&gt;&lt;P&gt;% Now go through and begin generating random points.&lt;/P&gt;&lt;P&gt;% Do it twice: once for testing, once for training.&lt;/P&gt;&lt;P&gt;for nDataset = 1:2,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if (nDataset==1)&lt;/P&gt;&lt;P&gt;nRowsLeft = nRows;&lt;/P&gt;&lt;P&gt;sOutputFile = sTrainFile;&lt;/P&gt;&lt;P&gt;nTotRows = nRows;&lt;/P&gt;&lt;P&gt;else&lt;/P&gt;&lt;P&gt;nRowsLeft = nTestRows;&lt;/P&gt;&lt;P&gt;sOutputFile = sTestFile;&lt;/P&gt;&lt;P&gt;nTotRows = nTestRows;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;nMisclass = 0;&lt;/P&gt;&lt;P&gt;nTrainingClass1 = 0;&lt;/P&gt;&lt;P&gt;nTrainingClassm1 = 0;&lt;/P&gt;&lt;P&gt;while (nRowsLeft &amp;gt; 0)&lt;/P&gt;&lt;P&gt;disp(sprintf('Rows left = %d',nRowsLeft));&lt;/P&gt;&lt;P&gt;nRowsNow = min(nBufferPoints,nRowsLeft);&lt;/P&gt;&lt;P&gt;nRowsLeft = nRowsLeft - nRowsNow;&lt;/P&gt;&lt;P&gt;mNewPoints = zeros(nRowsNow,nCols);&lt;/P&gt;&lt;P&gt;vPointCenters = zeros(nRowsNow,1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;% Determine which center each point should belong to&lt;/P&gt;&lt;P&gt;vRandomNumbers = rand(nRowsNow,1);&lt;/P&gt;&lt;P&gt;for i = nCenters:-1:1,&lt;/P&gt;&lt;P&gt;vCenterMatch = (vRandomNumbers &amp;lt;= vPointCdf(i));&lt;/P&gt;&lt;P&gt;vPointCenters([vCenterMatch]) = i;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;% Create a vector of training classes for each point&lt;/P&gt;&lt;P&gt;vTrainingClasses = zeros(nRowsNow,1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;% Within each class, generate an appropriate number of random points.&lt;/P&gt;&lt;P&gt;for i = 1:nCenters,&lt;/P&gt;&lt;P&gt;vIndices = (vPointCenters==i);&lt;/P&gt;&lt;P&gt;nPoints = sum(vIndices);&lt;/P&gt;&lt;P&gt;vTrainingClasses(vIndices) = vCenterClasses(i);&lt;/P&gt;&lt;P&gt;mNewPoints(vIndices,:) = round( ...&lt;/P&gt;&lt;P&gt;mvnrnd(mCenters(i,:),cCovariance{i},nPoints));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;% Count how many points are incorrectly classified&lt;/P&gt;&lt;P&gt;vFitClass = sign(mNewPoints(vIndices,:) * w - gamma * ...&lt;/P&gt;&lt;P&gt;ones(nPoints,1));&lt;/P&gt;&lt;P&gt;vZeroSpots = find(vFitClass==0);&lt;/P&gt;&lt;P&gt;vFitClass(vZeroSpots) = ones(length(vZeroSpots),1);&lt;/P&gt;&lt;P&gt;nMisclass = nMisclass + sum(vFitClass~=vCenterClasses(i));&lt;/P&gt;&lt;P&gt;end; %for&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;% Output the data points to disk&lt;/P&gt;&lt;P&gt;flatfile([mNewPoints vTrainingClasses],sOutputFile,1);&lt;/P&gt;&lt;P&gt;nTrainingClass1 = nTrainingClass1 + sum(vTrainingClasses==1);&lt;/P&gt;&lt;P&gt;nTrainingClassm1 = nTrainingClassm1 + sum(vTrainingClasses==-1);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;end; %while&lt;/P&gt;&lt;P&gt;disp(sprintf('Percent separable estimate = %4.2f%%\n',100*(1-nMisclass/nTotRows)));&lt;/P&gt;&lt;P&gt;disp(sprintf('Number class 1 points = %d\n',nTrainingClass1));&lt;/P&gt;&lt;P&gt;disp(sprintf('Number class -1 points = %d\n',nTrainingClassm1));&lt;/P&gt;&lt;P&gt;end; %for-nDataset&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 31 Aug 2011 21:01:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-translate-a-matlab-code-to-SAS-IML/m-p/59108#M366</guid>
      <dc:creator>flyingsohigh</dc:creator>
      <dc:date>2011-08-31T21:01:25Z</dc:date>
    </item>
    <item>
      <title>How to translate a matlab code to SAS IML</title>
      <link>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-translate-a-matlab-code-to-SAS-IML/m-p/59109#M367</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You don't say what kind of help you're looking for. For general pointers, see &lt;A href="http://blogs.sas.com/content/iml/2011/03/09/translating-a-matlab-program-into-the-sasiml-language-a-case-study/"&gt;http://blogs.sas.com/content/iml/2011/03/09/translating-a-matlab-program-into-the-sasiml-language-a-case-study/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can look up the various MATLAB functions at &lt;A href="http://www.mathworks.com/help/techdoc/"&gt;http://www.mathworks.com/help/techdoc/&lt;/A&gt; to see what they do.&amp;nbsp; I assume that you know what the code is supposed to be doing? If so, and assuming that you know SAS/IML, I suggest you try to translate as much as possible into SAS/IML and then ask specific SAS/IML questions. It looks like you'll need to use the following SAS/IML functions: J (for ones() and zeros(), RANDGEN (for rand()), LOC (for find()?), RandNormal (for mvnrnd()),...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For help with generating random uniform numbers, see &lt;A href="http://blogs.sas.com/content/iml/2011/08/24/how-to-generate-random-numbers-in-sas/"&gt;http://blogs.sas.com/content/iml/2011/08/24/how-to-generate-random-numbers-in-sas/&lt;/A&gt;&lt;/P&gt;&lt;P&gt;For help on sampling from multivariate normal with a given covariance, see &lt;A href="http://blogs.sas.com/content/iml/2011/01/12/sampling-from-the-multivariate-normal-distribution/"&gt;http://blogs.sas.com/content/iml/2011/01/12/sampling-from-the-multivariate-normal-distribution/&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 Sep 2011 00:09:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-IML-Software-and-Matrix/How-to-translate-a-matlab-code-to-SAS-IML/m-p/59109#M367</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2011-09-01T00:09:55Z</dc:date>
    </item>
  </channel>
</rss>

