BookmarkSubscribeRSS Feed

This function does not work and I do not understand why:

 

proc fcmp outlib=work.funcs.trial;
    function DatumKonvertieren(eingabe);
    JJJJMMTT=input(eingabe, 16.);

    /*Warum 16 statt 8 Stellen? Bei 8 Stellen scheidet mir das Programm MMTT weg und gibt nur JJJJ aus. Warum?*/
    Tag=put(int(JJJJMMTT - int(JJJJMMTT / 100)*100), z2.);
    Monat=put(int(int(JJJJMMTT / 100) - int(JJJJMMTT / 10000) * 100), z2.);
    Jahr=put(int(JJJJMMTT / 10000), z4.);

    /*Tag = int(JJJJMMTT - int(JJJJMMTT / 100)*100); Monat = int(int(JJJJMMTT / 100) - int(JJJJMMTT / 10000) * 100); Jahr = int(JJJJMMTT / 10000);*/
    /*Verkettung = catx('/', Tag, Monat, Jahr);*/
    Verkettung=input(catx('/', Tag, Monat, Jahr), DDMMYYS10.);
    return(Verkettung);
    endsub;
    

/* Festlegen des Suchpfades, wo SAS nach eigenen Funktionen suchen soll */
options cmplib=work.funcs;

data work.test;
    eingabe=19600103;
    ausgabe=DatumKonvertieren(eingabe);
run;

 

 

 

In the log I get the message

ERROR: An illegal argument is used in the function call in function 'INPUTN' in statement number 6 at line 9 column 4.
       The statement was:
    0     (9:4)      Verkettung = INPUT( CATX( "/", Tag="03", Monat="01", Jahr="1960" ), DDMMYYS10.(105024000) )
ERROR: Exception occurred during subroutine call.
eingabe=19600103 ausgabe=. _ERROR_=1 _N_=1

 

 

which I do not understand. I allready tried the Variations set in /*...*/.

Using catx without input the return is 0 (variation with put-commands) oder 3 (variation without put-commands).

 

Can anybody see me mistake? I tried allready the command

date_new = input (JJJJMMTT, yymmdd8.);

format date_new date10.;

but this did not work, too.

 

Regard, Phil

6 REPLIES 6
RW9
Diamond | Level 26 RW9
Diamond | Level 26

How can you even read that mass of text?  As for what it is supposed to be doing refer back to the documentation that a decent programmer would have written for it.  From the error message:

Verkettung = INPUT( CATX( "/", Tag="03", Monat="01", Jahr="1960" ), DDMMYYS10.(105024000) )

None of that line looks right to me (and please forgive me I would never ever use fcmp, nor would I accept any coder who did use it - principally for the obfuscated code, and secondly it doesn't even show as user code like macro does possibly why the above line looks so odd).  input takes a character string, and a format and returns a numeric.  ddmmyys10.(105024000) is not a valid format.  Putting  Tag="03" or the other ones is also not valid - refer to the manual on these functions.  

 

I would highly recommend that you first work out some code in base SAS, drop all the function parts and just use datastep.  Get your code working there.  Then see if it can be helped by some macro code, and of course heavily document it all.

Sorry, this does not helpt me at all and I do not want to be abused. I tried to exlpain, what I allready did to find a solution and that is not possible with few words.

 

I got the pattern for the code from someone other. It's had been the first time, I used this community and it will be the last time.

FreelanceReinh
Jade | Level 19

@anonymous_user wrote:

It's had been the first time, I used this community and it will be the last time.


This would be a pity. Don't be mistaken by the first impression. This community is really great. I started contributing in October 2015 and I'm still enthusiastic about it. I've learned a lot from many highly skilled programmers (including @RW9) and I enjoy helping others.

 

Some people have strong opinions about certain programming styles. Don't take that personally. In my experience, the atmosphere in this community is remarkably excellent.

 

If you speak German (like me), you can also post questions to the (much smaller) German subforum, CoDe SAS. I'll be happy to answer your questions there, too (in German).

 

Best regards,

 

Reinhard

Reeza
Super User

@anonymous_user wrote:

Sorry, this does not helpt me at all and I do not want to be abused. I tried to exlpain, what I allready did to find a solution and that is not possible with few words.

 


1. I'm pretty sure that RW9 response can be considered insensitive, but it's a far cry from "abuse". 

2. You didn't actually say what you were trying to do anywhere which is the actual problem. This situation is an example of the XY problem. 

 

The XY problem is a communication problem often found in help desk or similar situations, in which the cause of a problem is masked because the person asking for help has presented incomplete information as to the source of their problem. This ambiguity in the real source of a problem leads to wrong, inaccurate, or unhelpful solutions being offered. The issue arises when the person with the problem thinks that they themselves have a partial solution to their problem, and only ask for the parts they think they are "stuck" on. On the other side, the people offering to help lack information as to the root problem, and thus cannot provide ultimately useful information. The problem generally plays out according to a predictable pattern:

  1. Person 1 has a problem "X"
  2. Person 1 selects and attempts a solution "Y", which fails
  3. Person 1 asks Person 2 to fix solution "Y"
  4. Person 2 fixes solution "Y", however this does not fix problem "X" because solution "Y" was inadequate to solve it.
  5. Person 1 becomes frustrated with Person 2, believing Person 2 is incompetent or simply unable to solve the problem, while Person 2 is confused because they don't know what the real problem "X" even is.

The XY problem is commonly encountered in technical support or customer service environments where the end user has attempted to solve the problems on their own, and misunderstands the real nature of the problem, believing that their real problem (the "X") has already been solved, except for some small detail in their solution (the "Y"). The situation manifests itself when the end user asks about some seemingly inane detail which is disconnected from any useful end goal. The solution for the support personnel is to ask probing questions as to why the information is needed, in order to identify the root problem and redirect the end user away from an unproductive path of inquiry.

 

If you are resorting to any public forums you will encounter this issue across the board, regardless of forum, and StackOverflow is worse. You could choose to use neither but you're unlikely to get the help  you need either. So you can choose how you react/respond and simply ignore responses if they're not helpful. 

 

If you want to post a question and get helpful responses here's a simple recipe to follow:

 

1. What do you have, preferably as text because no one likes typing out data

2. What do you want, preferably that aligns with your input data. Specifying the logic helps. 

3. What have you tried so far to get there

4. What isn't working

 

@RW9 The forum constantly garbles code, especially if you try and modify it outside of the code editor, the pop up box that appears. For beginners, it's more helpful to explain that, rather than complain about it. 

 

FreelanceReinh
Jade | Level 19

Hallo @anonymous_user and welcome to the SAS Support Communities!

 

Just delete the "S" in "DDMMYYS10." and it will work. (At least it worked on my computer.)

 

However, how about this simplification?

proc fcmp outlib=work.funcs.trial;
function DatKonv(eingabe);
ausgabe = input(put(eingabe, 8.), yymmdd8.);
return(ausgabe);
endsub;
run;

As to your question why input(eingabe, 8.) cuts off the last four digits (month and day):

eingabe is a numeric variable, but the INPUT function expects a character string, as RW9 has already pointed out. Therefore, SAS automatically converts eingabe to a character string by using the standard format BEST12. The result is right-aligned! As a consequence, INPUT applies the 8. informat to a string of length 12 consisting of four blanks followed by the 8 digits of eingabe. This means that only the blanks plus the first four digits of eingabe are read -- resulting in the year value.

 

In my simplified function definition I used the PUT function to perform the numeric-to-character conversion correctly.

 

ballardw
Super User

If the purpose of this ugly code is to extract date information from a variable that is character and in the format yyyymmdd then you are probably wasting a LOT of time since a proper input statement likely would work.

If eingabe is actually numeric:

data work.test;
  eingabe = 19600103;
   mydatevar = input(put(eingabe,8.),yymmdd8.);
   format mydatevar date9.;
run;

or if eingabe is character:

 

data work.test;
   eingabe = '19600103';
   mydatevar = input(eingabe,yymmdd8.);
   format mydatevar date9.;
run;

SAS supplies a fairly large number of tools for dealing with variety of date, time and datetime constructs.

 

 

 

 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 6 replies
  • 1886 views
  • 1 like
  • 5 in conversation