BookmarkSubscribeRSS Feed
EyalGonen
Lapis Lazuli | Level 10

שלום לכולם,

 

בעקבות שאלה שנשאלתי היום גיליתי יכולת שלא הייתי מודע לה והיא שאפשר לייצר Informat שמוגדר על ידי ביטוי Perl. הרעיון הוא להגדיר בשפת הביטויים הנפוצה Perl את מבנה הקלט כולל אפשרות לבצע החלפות של תווים בקלט בתווים אחרים ו/או להוסיף תווים לקלט על מנת שיתאימו למבנה סטנדרטי לדוגמה אם בקלט מופיע החודש כ "1" ולא כ "01" כנדרש. 

 

להלן דוגמה נחמדה שהכנתי שמשלימה את התאריך החלקי לתאריך מלא. שימו לב שהקלט הוא מספר רגיל בעוד הפלט לאחר הפעלת ה informat עם ה Perl הוא תאריך SAS תקני וכמו כן שימו לב שבשני המספרים אין את היום בחודש וכן שמספר החודש הוא לפעמים ספרה אחת (7) ובמקרה השני שתי ספרות (12). ה Informat מתמודד עם זה על ידי זיהוי שני המקרים והשלמת ה "חלקים החסרים".

 

proc format;
  invalue mmyy (default=8)
             's/(^\d{6}$)/01\1/o'  (regexpe)=[ddmmyy8.]
             's/(^\d{5}$)/010\1/o' (regexpe)=[ddmmyy8.]		  
;
run;

data test;
	infile cards;
	input d:mmyy6.;
	format d ddmmyy10.;
cards;
72021
122021
;
run;

הפלט המתקבל הוא שתי רשומות עם תאריכי SAS תקניים הראשון 01/07/2021 והשני 01/12/2021

 

אייל

2 REPLIES 2
AMSAS
SAS Super FREQ

@EyalGonen Can you post your question in English, you are more likely to get a response then.
I ran google translate on it, and it looks like you are asking about Using Regular Expressions in PROC FORMAT there's a link on that page to an example:

Example 10: Creating a Format Using Perl Regular Expressions 

EyalGonen
Lapis Lazuli | Level 10

Hi @AMSAS 

 

It is not a question but more of an announcement to our local SAS users in Israel about this capability 🙂

I just updated my post with an example.

 

Cheers,

Eyal

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

Discussion stats
  • 2 replies
  • 840 views
  • 2 likes
  • 2 in conversation