data test10(keep=HSI);
infile datalines dlm=" ";
input a b c HSI e;
format HSI comma8.;
datalines;
2017-04-27 24,520.09 24,717.44 24,455.12 24,698.48 0.00
2017-04-26 24,576.08 24,637.85 24,515.23 24,578.43 0.00
2017-04-25 24,455.94 24,455.94 24,201.91 24,455.94 0.00
2017-04-24 24,139.48 24,206.44 23,958.18 24,139.48 0.00
2017-04-21 24,132.06 24,190.14 23,991.87 24,042.02 0.00
2017-04-20 23,945.67 24,058.87 23,827.07 24,056.98 0.00
2017-04-19 23,768.68 23,893.14 23,723.87 23,825.88 0.00
2017-04-18 24,077.50 24,276.31 23,892.59 23,924.54 0.00
2017-04-13 24,203.80 24,378.38 24,158.16 24,261.66 0.00
2017-04-12 24,050.75 24,313.50 23,994.13 24,313.50 0.00
2017-04-11 24,308.04 24,318.15 24,007.85 24,088.46 0.00
2017-04-10 24,271.48 24,314.66 24,215.54 24,262.18 0.00
2017-04-07 24,169.88 24,268.39 23,982.40 24,267.30 0.00
2017-04-06 24,333.23 24,381.63 24,210.69 24,273.72 0.00
2017-04-05 24,326.30 24,400.80 24,166.01 24,400.80 0.00
2017-04-03 24,261.48 24,261.48 24,162.55 24,261.48 0.00
2017-03-31 24,235.70 24,329.98 24,105.38 24,111.59 0.00
2017-03-30 24,301.09 24,431.12 24,250.40 24,301.09 0.00
2017-03-29 24,392.05 24,470.66 24,330.70 24,392.05 0.00
2017-03-28 24,322.68 24,360.00 24,274.52 24,345.87 0.00
2017-03-27 24,378.03 24,434.90 24,138.78 24,193.70 0.00
2017-03-24 24,358.27 24,420.77 24,263.17 24,358.27 0.00
2017-03-23 24,393.66 24,466.73 24,271.26 24,327.70 0.00
2017-03-22 24,332.14 24,380.42 24,207.10 24,320.41 0.00
2017-03-21 24,647.67 24,656.65 24,500.35 24,593.12 0.00
2017-03-20 24,340.66 24,501.99 24,312.57 24,501.99 0.00
2017-03-17 24,288.59 24,385.81 24,237.97 24,309.93 0.00
2017-03-16 24,071.60 24,288.28 24,003.75 24,288.28 0.00
2017-03-15 23,714.25 23,842.81 23,645.51 23,792.85 0.00
2017-03-14 23,860.33 23,918.12 23,768.34 23,827.95 0.00
;
run;
I want to extract data in the fourth column (i.e. 24,698.48 to 23,827.95).
I tried to use dlm=" " to specific only Blank will be the delimiter, but I guess there is a comma between the number so that the program stop running. Can anyone help me to do this?
Informats are your friend:
data test10 (keep=hsi); infile datalines dlm=" "; informat a yymmdd10. b c hsi e comma9.; input a b c hsi e; format hsi comma8.2; datalines; 2017-04-27 24,520.09 24,717.44 24,455.12 24,698.48 0.00 2017-04-26 24,576.08 24,637.85 24,515.23 24,578.43 0.00 2017-04-25 24,455.94 24,455.94 24,201.91 24,455.94 0.00 ; run;
Informats are your friend:
data test10 (keep=hsi); infile datalines dlm=" "; informat a yymmdd10. b c hsi e comma9.; input a b c hsi e; format hsi comma8.2; datalines; 2017-04-27 24,520.09 24,717.44 24,455.12 24,698.48 0.00 2017-04-26 24,576.08 24,637.85 24,515.23 24,578.43 0.00 2017-04-25 24,455.94 24,455.94 24,201.91 24,455.94 0.00 ; run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.