Search code examples
sas

I am trying to use sas first.value, but get different results then expected


I am trying to run this code for a basic presentation:

[![DATA a ;
    INFILE DATALINES DSD DLM='|'  ;
    LENGTH Actor_Name $20 ;
    INPUT Actor_Name $ Total ;
    DATALINES ;
    Julie Maze | 1
    Julie Maze | 1
    Julie Maze | 1
    Marry Dryn | 1
    Marry Dryn | 1
    Marry Dryn | 1
    ;
RUN ;

PROC SORT DATA = work.a OUT = a_sorted ;
    BY Actor_Name ;
RUN ;

DATA b ;
    SET work.a_sorted ;
    BY Actor_Name ;
    IF first.Actor_Name
    THEN counter = 1 ;
    ELSE counter + 1 ;
RUN ;][1]][1]

I expect to see 6 data lines, where the new column 'counter' would state 1,2,3 and 1,2,3 for each Actor_Name group. But I get 1,2,3 and 1,2,1


Solution

  • The 6th sorted data line probably has a control character in it, perhaps a tab?

    Running what you posted though gives 1,2,3,1,2,3. Your actual data lines could have hard space 'A0'x. Try PUT name $HEX40.; to see in log what you actually have.