Hi,
new to SAS programming, tried to import raw data but how to convert the number follow with negative sign to negative number as the output missing value.
tried tp find solution but unable to solve it(believe wrong method), appreciated if you could spend sometime to guide me.
DATA TESTING;
INFILE DATALINES DLM='|' MISSOVER;
INPUT H :$ G :$ K;
IF MISSING(K) THEN
K=CATX('-',SUBSTR(K,1,LENGTH(K)-1));
DATALINES;
D | ABC
E | EFB | 456
f | WWL | 567-
;
data testing; infile datalines dlm='|' missover; input h $ g $ k $; k_num=input(cats(ifc(index(k,"-")>0,"-",""),tranwrd(k,"-","")),best.); datalines; D | ABC E | EFB | 456 f | WWL | 567- ; run;
You will see several things from the above. First, I have used a code window ({i} above where you post) this distinguishes code from text. Secondly I use consitent lower case, and 2 spaces indentation in my code for readablitiy. Finally, I use the input() function which takes character and converts to number. First I decide if there is a "-" in the text, if so its negative, and concatenate a miinus with the number then input.
data testing; infile datalines dlm='|' missover; input h $ g $ k $; k_num=input(cats(ifc(index(k,"-")>0,"-",""),tranwrd(k,"-","")),best.); datalines; D | ABC E | EFB | 456 f | WWL | 567- ; run;
You will see several things from the above. First, I have used a code window ({i} above where you post) this distinguishes code from text. Secondly I use consitent lower case, and 2 spaces indentation in my code for readablitiy. Finally, I use the input() function which takes character and converts to number. First I decide if there is a "-" in the text, if so its negative, and concatenate a miinus with the number then input.
@RW9 wrote:
data testing; infile datalines dlm='|' missover; input h $ g $ k $; k_num=input(cats(ifc(index(k,"-")>0,"-",""),tranwrd(k,"-","")),best.); datalines; D | ABC E | EFB | 456 f | WWL | 567- ; run;You will see several things from the above. First, I have used a code window ({i} above where you post) this distinguishes code from text. Secondly I use consitent lower case, and 2 spaces indentation in my code for readablitiy. Finally, I use the input() function which takes character and converts to number. First I decide if there is a "-" in the text, if so its negative, and concatenate a miinus with the number then input.
There is an INFORMAT for that but you get the programming for job security award.
data testing;
infile datalines dlm='|' missover;
input h $ g $ k :Trailsgn.;
*k_num=input(cats(ifc(index(k,"-")>0,"-",""),tranwrd(k,"-","")),best.);
datalines;
D | ABC
E | EFB | 456
f | WWL | 567-
g | WWL | -567
;;;;
run;
proc print;
run;
Yes, didn't know about that informat. As for job security, if I wanted that I would have created at least one macro, with a macro list, and an Excel paramters file
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.