Help using Base SAS procedures

Problems with PUTVARN() and LOCATEN()

Reply
N/A
Posts: 0

Problems with PUTVARN() and LOCATEN()

hello,

after several hours of working I am somehow desperated.

I need to change entries of a table (table1) depending on the settings in another table (table2). so far so good, first I decided to check for the specific value in table2 with the command LOCATEN(). the SAS system returned with the error that it doesnt know the function LOCATEN().

well... I thought many ways lead to Rome, so I redesigned it and created an array in table1 with the settings from table2 (because GETVARN() was working)... but now, when I try to change the value with call PUTVARN(), then the SAS system returns with the same error: unknown routine.

there is no information about that problem in the help system, only that both functions (LOCATEN() and PUTVARN()) are available... but I dont know why both are not working.

Any help is appreciated
Super Contributor
Super Contributor
Posts: 3,174

Re: Problems with PUTVARN() and LOCATEN()

Suggest you share your SAS code, also paste the SAS log output where you are getting the error.

Scott Barry
SBBWorks, Inc.
N/A
Posts: 0

Re: Problems with PUTVARN() and LOCATEN()

this is the code sniplet:

data _null_;

array mname_trans[200] $ mnametrans1-mnametrans200;

ntrans = 0;

dsid = OPEN( 'merk' );
nobs = ATTRN( dsid, 'NOBS' );

do i=1 to nobs;
rc = fetchobs( dsid, i );
mname = getvarc( dsid, VARNUM( dsid, 'NAME' ) );
mmethod = getvarc( dsid, VARNUM( dsid, 'METHODE' ) );
if mmethod eq 'S%' then
do;
ntrans = ntrans + 1;
mname_trans[ntrans] = mname;
end;
end;

rc=CLOSE( dsid );

dsid = OPEN( 'V_Daten' );
nobs = ATTRN( dsid, 'NOBS' );
nvar = ATTRN( dsid, 'NVARS' );

do i=1 to nvar;

vname = VARNAME( dsid, i );

do k=1 to ntrans;

if ( mname_trans eq vname ) then do;

do j=1 to nobs;

rc = fetchobs( dsid, j );
value = GETVARN( dsid, i );

if value le 10.0 then value = 1;
else if value le 20.0 then value = 2;
else if value le 30.0 then value = 3;
else if value le 40.0 then value = 4;
else if value le 50.0 then value = 5;
else if value le 60.0 then value = 6;
else if value le 70.0 then value = 7;
else if value le 80.0 then value = 8;
else value = 9;

call putvarn( dsid, i, value );

end;

leave; /* tanslation found, leave do loop */

end;

end;

end;

rc=CLOSE( dsid );

keep [KFAKTOR1] [KORT] [KJAHR] [ADICH] [AWDA] [AFUS_B] [APHYPZE_B] [AM_NWI2];

run;


and this is what SAS returns:

665 if value le 10.0 then value = 1;
666 else if value le 20.0 then value = 2;
667 else if value le 30.0 then value = 3;
668 else if value le 40.0 then value = 4;
669 else if value le 50.0 then value = 5;
670 else if value le 60.0 then value = 6;
671 else if value le 70.0 then value = 7;
672 else if value le 80.0 then value = 8;
673 else value = 9;
674
675 call putvarn( dsid, i, value );
_______
_______
_______
251
251
251
FEHLER 251-185: Die Subroutine PUTVARN ist unbekannt oder nicht verfügbar. Prüfen Sie die (=> translation: the subroutine PUTVARN is either unknown or not available. check the)
FEHLER 251-185: Die Subroutine PUTVARN ist unbekannt oder nicht verfügbar. Prüfen Sie die
FEHLER 251-185: Die Subroutine PUTVARN ist unbekannt oder nicht verfügbar. Prüfen Sie die
Schreibweise. (=> translation: spelling)
Schreibweise.
Schreibweise.
Entweder wurde sie nicht im Pfad ausführbarer Images gefunden oder (=>translation: either it wasnd found in the path of executable images or)
Entweder wurde sie nicht im Pfad ausführbarer Images gefunden oder
Entweder wurde sie nicht im Pfad ausführbarer Images gefunden oder
falsche/unvollständige Informationen über den Subroutinendeskriptor lagen vor. (=> translation: wrong/incomplete information about the subroutine descriptor were available)
falsche/unvollständige Informationen über den Subroutinendeskriptor lagen vor.
falsche/unvollständige Informationen über den Subroutinendeskriptor lagen vor.
N/A
Posts: 0

Re: Problems with PUTVARN() and LOCATEN()

this is another test I ran for the LOCATEN() problem:

76 data test;
77 array tab[10] tab1-tab10;
78 do i=1 to 10;
79 tab = i;
80 end;
81 run;
82
83 proc print data=test;
84 run;
85
86 data test2;
87 set test;
88
89 id = OPEN( 'test' );
90 row = locaten( id, varnum( id, 'tab1'), 1 );
-------
68
FEHLER 68-185: Funktion LOCATEN ist unbekannt oder nicht ausführbar. (same error: unknown funciton)

91 run;
N/A
Posts: 0

Re: Problems with PUTVARN() and LOCATEN()

this is the SAS version I am running: SAS 9.1.3 Service Pack 1
Valued Guide
Posts: 2,174

Re: Problems with PUTVARN() and LOCATEN()

base SAS cannot use scl-type function OPEN() to open dataset for output. Check the function in base SAS Language Reference.
Why use these functions - it looks harder than base SAS?
Alternatively, use SAS/AF directly with compiled SCL instead of the base SAS environment. Then modify your OPEN() for output.

Good luck
peterC
N/A
Posts: 0

Re: Problems with PUTVARN() and LOCATEN()

thank you for the answers, although they do not help me very much Smiley Sad

Basically I am a C++ developper whom was given the task to write a SAS skript that is called from a PiafSTAT program (which is a German analytical tool for research). So in the end I am a bloody newby with SAS who has no problems with open, close, get and put commands, but got problems with thinking in the SAS way.

Well, back to topic: I wonder, wy the SCL-command GETVARN() is working and PUTVARN() not, as both are contents of the SCL-language.

and I have no clue how to activate the SCL-language.

@peter: I have no clue about SAS/AF and fear, that the combination of PiafSTAT and SAS doesnt let me choose the envirenment. And I dont hava a clue how to check for the function for PUTVARN() in base SAS language. I worked the whole days through the help system but couldnt find it. So I hope to get help here in the forum.
Super Contributor
Super Contributor
Posts: 3,174

Re: Problems with PUTVARN() and LOCATEN()

I believe you are attempting to use SAS Component Language (SCL) elements in your program, which are not available.

Scott Barry
SBBWorks, Inc.

SAS(R) Component Language 9.2: Reference, Introduction:
http://support.sas.com/documentation/cdl/en/sclref/59578/HTML/default/a000308113.htm
Super Contributor
Super Contributor
Posts: 365

Re: Problems with PUTVARN() and LOCATEN()

Hello Saracaeus,

You said "I need to change entries of a table (table1) depending on the settings in another table (table2)". This sounds too general. If you could give an example of tables 1 and 2 and what would you like to achieve, then it would be much easier to help you with SAS code.

Sincerely,
SPR
N/A
Posts: 0

Re: Problems with PUTVARN() and LOCATEN()

table1 contains test data... but some of them are given in % (0-100) => method "S%" and some of them are given in marks (1-9) => method "BON19"

table2 specifies the method of the data.

here an example:

table1

year density1 density2 ..... densityX
=============================
2004 100 2 56
2005 89 4 78
2006 45 7 98


table2:

name method
================
density1 S%
density2 BON19
.
.
.
densityX S%

in the final working table all data must be stored as marks, the translation mechanism is the following:

percentage mark
=================
le 10% 1
le 20% 2
le 30% 3
le 40% 4
le 50% 5
le 60% 6
le 70% 7
le 80% 8
gt 80% 9

so I need to recalculate all these columns that are stored in %.

during runtime it decides, what and how many data I get. the colmun names are not always density1 ... densityX... they can vary... they are available in a special symbol (e.g. [ANAMES]), this symbol is translated by PiafSTAT to the real names => [ANAMES] will be resolved to: "density1 density2 density3 density4" ). so if you write "BY [ANAMES];" ... => then SAS will see: "BY density1 density2 density3 density4;"

I hope I explained clear enough.

I work since 20 hours at this problem. As a c++ developper I have a complete different way of thinking, I fear, I am desperating with that small problem.

Thank you for any help,
Tom
N/A
Posts: 0

Re: Problems with PUTVARN() and LOCATEN()

... and the irony is: if PUTVAR() would work, I would have solved this problem already Smiley Sad
Super Contributor
Super Contributor
Posts: 365

Re: Problems with PUTVARN() and LOCATEN()

Hello Saraceus,

This is the code for your task if I understood it corretly:
[pre]
/* Writing name and method values into macro variables */;
proc SQL noprint;
select COUNT(*) into :n from table2;
%let n=%trim(&n);
select name into :d1-:d&n from table2;
select method into :m1-:m&n from table2;
quit;
/* Final results are in variables r1-r&n */;
%macro a;
%local i;
data r (drop=i);
set table1;
%do i=1 %to &n;
/* Checking method */
if UPCASE("&&m&i") = "S%" then do;
if &&d&i <= 10 then r&i=1;
else if 10 < &&d&i <= 20 then r&i=2;
else if 20 < &&d&i <= 30 then r&i=3;
else if 30 < &&d&i <= 40 then r&i=4;
else if 40 < &&d&i <= 50 then r&i=5;
else if 50 < &&d&i <= 60 then r&i=6;
else if 60 < &&d&i <= 70 then r&i=7;
else if 60 < &&d&i <= 80 then r&i=8;
else if 80 < &&d&i then r&i=9;
end;
else r&i=&&d&i;
%end;
run;
%mend;
%a[/pre]
Sincerely,
SPR
N/A
Posts: 0

Re: Problems with PUTVARN() and LOCATEN()

hello SPR,

thousand thanks for your reply Smiley Happy

I want to understand the code, so pls excuse me if I have some questions:

1) now the final results are in r1-r&n => I need them written back into table1, or did I misunderstand and due to the data r; set table1; => all data is in table r?

2) if &&d&i <= 10 then r&i=1;
=> isn't &&d&i the macro variable from the SQL proc? if so, it contains the names of table2, not the values Smiley Sad... somehow I need basic understanding of all the r&i and &&d&i... where can I read about the '&'? or is there any easy explanation of referencing and dereferencing (what I think is the mysterious &)

thank you in advance.
Tom
N/A
Posts: 0

Re: Problems with PUTVARN() and LOCATEN()

OK, while working a bit with the code I think I start to understand

in &d&i is the name of the variable, so & &d&i refers to the value of the name of the variable, right?

if this is correct I will figure it out Smiley Happy

Tom
Super Contributor
Super Contributor
Posts: 365

Re: Problems with PUTVARN() and LOCATEN()

Hello Tom,

Sorry, the correct code for macro %a is like this:
[pre]
%macro a;
%local i;
data r;
set table1;
%do i=1 %to &n;
/* Checking method */
if UPCASE("&&m&i") = "S%" then do;
if &&d&i le 10 then &&d&i=1;
else if 10 lt &&d&i le 20 then &&d&i=2;
else if 20 lt &&d&i le 30 then &&d&i=3;
else if 30 lt &&d&i le 40 then &&d&i=4;
else if 40 lt &&d&i le 50 then &&d&i=5;
else if 50 lt &&d&i le 60 then &&d&i=6;
else if 60 lt &&d&i le 70 then &&d&i=7;
else if 60 lt &&d&i le 80 then &&d&i=8;
else if 80 lt &&d&i then &&d&i=9;
end;
%end;
run;
%mend;
%a
[/pre]
SPR
Ask a Question
Discussion stats
  • 32 replies
  • 188 views
  • 0 likes
  • 6 in conversation